[英]nodejs request module returning ECONNREFUSED on localhost
I am trying to make an api call to my localhost but I always get Error: connect ECONNREFUSED 127.0.0.1:5005 at Object.exports._errnoException (util.js:1022:11)
我正在尝试对我的本地主机进行 api 调用,但我总是收到Error: connect ECONNREFUSED 127.0.0.1:5005 at Object.exports._errnoException (util.js:1022:11)
var url = `http://127.0.0.1:5005/api/entities/myEndpoint?id=121`;
var options = {
url: url
};
request.get(options, function(err, response, body) {
console.log(err, response,body);
});
It does work if I use an IP instead of localhost如果我使用 IP 而不是本地主机,它确实有效
Check if your server has bound the port to its external IP only.检查您的服务器是否仅将端口绑定到其外部 IP。 On Linux, check netstat -tulpen | grep 5005
在 Linux 上,检查netstat -tulpen | grep 5005
netstat -tulpen | grep 5005
. netstat -tulpen | grep 5005
。 The output will contain the Server's listener address, eg 0.0.0.0:5005
or ::5005
both means that the server listens on all Interfaces for port 5005
.输出将包含服务器的侦听器地址,例如0.0.0.0:5005
或::5005
都表示服务器侦听端口5005
的所有接口。
If your result is something like <ip address>:5005
where ip address
is different from 127.0.0.1
that means that the server listens on that ip and port combination only and cannot be accessed using localhost
, even if you are logged into the server.如果您的结果类似于<ip address>:5005
,其中ip address
与127.0.0.1
不同,这意味着服务器仅侦听该 ip 和端口组合并且无法使用localhost
访问,即使您已登录到服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.