Worklight 6.1 - 如何在适配器级别的请求标头中设置x-forwarding Ip地址

时间:2014-06-16 12:13:36

标签: ibm-mobilefirst worklight-adapters

我正在使用worklight 6.1并面临一些问题,即在请求时获取我们想要的适配器级别的x-forwarding ip地址。所以现在我正在客户端发送客户端IP地址,如下所示

WL.Device.getNetworkInfo(function (networkInfo) {
                    console.log(networkInfo.ipAddress); 
                    ipadd = networkInfo.ipAddress;
                    reqParams["fldAppipAddress"] = networkInfo.ipAddress;
                });
                var invocationData = {
                        adapter : "Login",
                        procedure : "Login",
                        parameters : [id,reqParams,ipadd],
                        compressResponse : true
                };

和适配器端我正在设置这样的标题

var request={
             method:'POST',
             returnedContentType:'xml',
             path:serverPathIs,
             headers:{"User-Agent":"","App-Version":"1.6","X-Forwarded-For":Ipaddress},
             cookies: {"JSESSIONID":cookiestr},
             parameters:jsonstr,
     };

即使这样做了,我也没有获得x-forward ip,请建议正确的方法。

如何在http请求的标头中设置x-forwarded-for

@Anton

function GetAPICal(fldjsessionid,jsonstr,pass,uid,Ipaddress){
  WL.Logger.error(jsonstr);
  WL.Logger.info(jsonstr);
    //newjson={"fldPassword":enc(pass)};

    var output = {};
    output = jsonConcat(jsonstr, newjson);
     serverPathIs=getServletPathInfo();
     if(fldjsessionid){
         cookieSplit = fldjsessionid.split('!');
        cookiestr = cookieSplit[0]+"!"+cookieSplit[1];
     }
     else{
         cookiestr="123";
     }
     var request={
             method:'POST',
             returnedContentType:'xml',
             path:serverPathIs,
             headers:{"User-Agent":"","App-Version":"1.6","X-Forwarded-For":Ipaddress},
             cookies: {"JSESSIONID":cookiestr},
             parameters:output,
     };

     var req = WL.Server.getClientRequest();




     var response = WL.Server.invokeHttp(request);


     return response;

}

1 个答案:

答案 0 :(得分:0)

你到底想要达到什么目的?从客户端>适配器请求获取x-forwarded-for标头,并在adapter->后端请求中使用它?