在其他客户端中未发生的node.js的ECONNREFUSED错误 [英] ECONNREFUSED error with node.js that does not occur in other clients

查看:106
本文介绍了在其他客户端中未发生的node.js的ECONNREFUSED错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用node.js客户端发出http请求,但出现了ECONNREFUSED错误.当我用浏览器或curl(1)发出似乎相同的请求时,效果很好

I'm making an http request with the node.js client, and I get an ECONNREFUSED error. When I make what appears to be the same request with my browser or curl(1), it works just fine

这是节点请求:

var options = {
  host: 'localhost',
  port: 8080,
  path: '/explorers/1.0/agegroup',
  method: 'GET'
};

var req = http.request(options, function(res) {
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});

req.on('error', function(e) {
  console.log(e);
});

req.end();

它给了我错误:

{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }

但是当我与其他客户端(在这种情况下为curl)发出相同的请求时:

But when I make the same request with a different client (curl in this case):

$ curl http://localhost:8080/explorers/1.0/agegroup
{... response JSON ...}

其他说明:

  • 我尝试将主机更改为www.google.com,将端口更改为80,并且节点成功建立了连接

  • I've tried changing the host to www.google.com and the port to 80, and node makes the connection successfully

我已经尝试过更改服务器的端口,但我仍然可以向除node.js(仍然得到ECONNREFUSED)

I've tried changing the port of the server, and I can still make requests with all clients but node.js (which still gets ECONNREFUSED)

我要连接的服务器是 CherryPy WSGI服务器.当我尝试连接到localhost:8080上的node服务器时,它工作正常,这使我认为这是服务器的问题,除了其他客户端可与CherryPy服务器一起使用.

The server to which I'm connecting is the CherryPy WSGI Server. When I try connecting to a node server at localhost:8080, it works fine, which would make me think it's the server's problem, except other clients work with the CherryPy server.

我尝试使用与浏览器相同的标头,但是那没有用,而且问题似乎还是在TCP级别上,因此HTTP标头应该不成问题.

I've tried using the same headers that my browser is using, but that doesn't work, and it seems like the problem is at the TCP level anyway, so HTTP headers shouldn't be an issue.

我的node请求有什么问题?

推荐答案

我想有时候您只需要摆脱问题即可.

I guess sometimes you just need to step away from the problem...

我找到了一个解决方案,但是它似乎并没有回答这个问题,而且我也不是很喜欢.

I found a solution, but it doesn't seem to answer the question, and I don't really like the it.

我将CherryPy服务器配置更改为在127.0.0.1而不是localhost服务,并且node客户端开始工作.

I changed the CherryPy server configuration to serve at 127.0.0.1 instead of localhost, and the node client started working.

这篇关于在其他客户端中未发生的node.js的ECONNREFUSED错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆