서버의 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 주소를 보내는 것과 관련이 있다고 믿습니다. 머리글에 정확하게 표시하고 있습니까?