[英]Make https request from Node js http server
我的實時站點是https://example.com 。 現在我已經在http://example.com:8081上創建了一個節點 js 服務器。 我有以下代碼:
var options = {
host: 'https://example.com',
port: 443,
path: '/scanner/scoutdata',
method: 'GET'
};
and sending request like this:
http.request(options, function(res){
//my code here.
});
現在,當我在 linux 服務器中運行此腳本時收到 302 錯誤消息。 我不能從同一個域下的http://節點服務器調用帶有https://的 url 嗎? 我應該在HTTPS創建我的節點JS服務器://與HTTPS通話網址://
如果在端口 443(SSL 端口)上聯系服務器,請使用https.get()
而不是http.get()
)。
302 響應只是告訴您端口和協議不匹配,它希望它們匹配。 因此,在端口 80 上使用 http,在端口 443 上使用 https。
你可以使用 axios
var axios = require('axios');
axios.get("https://example.com:443/scanner/scoutdata").then(function (response) {
console.log(response.data);
});
請嘗試使用請求模塊,因為我將代碼放在下面-
request("https://example.com:443/scanner/scoutdata", function(error, response, body) {
console.log(body);
});
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.