我正在尝试通过 HTTPS 请求将服务器的 IP(在本例中为我的计算机公共 IP)发送到另一台服务器以访问其 API。我已经完成了服务器身份验证,并且有了我的不记名令牌。我正在使用 Express 和 NPM 进行服务器端编程。我得到我的IP地址如下:
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 地址有关。我在标题中正确发送了吗?