Javascript 从节点js http服务器发出https请求
我的生活网站是。现在,我已经在上创建了一个节点js服务器。我有以下代码:Javascript 从节点js http服务器发出https请求,javascript,node.js,express,https,socket.io,Javascript,Node.js,Express,Https,Socket.io,我的生活网站是。现在,我已经在上创建了一个节点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. }); 现在,当我
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://的URL,请尝试使用请求模块,因为我将代码放在下面-
request("https://example.com:443/scanner/scoutdata", function(error, response, body) {
console.log(body);
});
感谢如果在端口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);
});