Does the IBM Worklight HTTP Adapter send/support sending a User-Agent header?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 03:26:31

问题


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



来源:https://stackoverflow.com/questions/25569335/does-the-ibm-worklight-http-adapter-send-support-sending-a-user-agent-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!