Node.js Nodejs-https.request错误:connect-ECONNREFUSED
我试图在我的节点服务器中进行http调用(我尝试的URL是skackexchange公共URL),下面是代码Node.js Nodejs-https.request错误:connect-ECONNREFUSED,node.js,econnrefused,Node.js,Econnrefused,我试图在我的节点服务器中进行http调用(我尝试的URL是skackexchange公共URL),下面是代码 httpsServer.js var https = require('https'); function httpsRequest() { var options = { hostname: 'api.stackexchange.com', path: '/2.2/answers', method: 'GET' };
httpsServer.js
var https = require('https');
function httpsRequest() {
var options = {
hostname: 'api.stackexchange.com',
path: '/2.2/answers',
method: 'GET'
};
var req = https.request(options, (res) => {
res.on('data', function (data) {
console.dir(data);
});
req.end();
});
req.on('error', function (e) {
console.error(e);
});
}
httpsRequest();
我在我的控制台中做了节点httpsServer
但是我得到了下面的错误
Error:
{ Error: connect ECONNREFUSED xxx.xxx.xxx.xx:443
at Object.exports._errnoException (util.js:1050:11)
at exports._exceptionWithHostPort (util.js:1073:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1093:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: 'xxx.xxx.xxx.xx',
port: 443 }
注意:我在代理服务器后面
我做错了什么?如果是因为我支持代理,有没有办法让它工作?您的req.end()
放错了位置。您需要先结束请求,然后才能从服务器获得响应
var https = require('https');
function httpsRequest() {
var options = {
hostname : 'api.stackexchange.com',
path : '/2.2/answers',
method : 'GET'
};
var req = https.request(options, (res) => {
res.on('data', function (data) {
console.dir(data);
});
});
req.on('error', function (e) {
console.error(e);
});
req.end(); // correct place
}
httpsRequest();
尝试在
mysql.conf
中设置,注释跳过网络
。这个错误只是MySQL服务器的错误配置。否则,你可以尝试这个答案,如果它仍然不工作。在我的情况下,插座只是挂断了一段时间后。