Do IBM Worklight HTTP Adapters (in 6.1) send a User-Agent header by default when invoking a back-end service using WL.Server.invokeHttp
? What is it's value? Assuming the answer is no, can we add one?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
In the adapter you can get the user agent the client sent like this:
var clientRequest = WL.Server.getClientRequest();
var userAgent = clientRequest.getHeader("User-Agent");
If you then want to pass this header along to a backend service:
var input = {
method :'get',
path : 'your/path',
headers: {
"User-Agent" : userAgent,
}
};
var result=WL.Server.invokeHttp(input);
回答2:
When you invoke an adapter procedure, you can inspect the network using a tool such as Wireshark. There you will see that a User-Agent header is sent. This header is automatically added by the underlying Apache HTTPClient.
That said, you can add your own headers. Per the user documentation for WL.Server.invokeHttp
:
Parameters:
options - The invokeHttp function accepts the following JSON block of parameters:
...
...
...
headers. Optional. Defines the headers for the HTTP request.
For example:
var input = {
method : 'get',
headers: {foo: 'bar'},
path : '/mypath'
};
return WL.Server.invokeHttp(input);
As for its value, it may not have any value for you. It is just part of the standard.
See here for more (or google for additional information): HTTP request header: UserAgent variable