我试图将服务器的IP(在这种情况下,我的计算机公共IP)发送到HTTPS请求中的另一台服务器以访问其API。我已完成服务器身份验证,并拥有我的不记名令牌。我正在使用Express和NPM进行服务器端编程。我得到我的IP地址如下:在请求头中发送IP NPM
var ipAddress;
publicIp.v4().then(ip => {
ipAddress = ip;
console.log(ip);
});
我正在提出如下要求。
request({
//Set the request Method:
method: 'POST',
//Set the headers:
headers: {
'Content-Type': 'application/json',
'Authorization': "bearer "+ token, //Bearer Token
'X-Originating-Ip': ipAddress //IP Address
},
//Set the URL:
url: 'end point url here',
//Set the request body:
body: JSON.stringify('request body here'
}),
}, function(error, response, body){
//Alert the response body:
console.log(body);
console.log(response.statusCode);
});
}
我收到了401错误。我已经完成了研究,我相信它与发送IP地址有关。我是否正确地在标题中发送它?