可能导致“连接超时"的原因是什么? URL在浏览器中工作时出现错误? [英] What could cause "connect ETIMEDOUT" error when the URL is working in browser?

查看:230
本文介绍了可能导致“连接超时"的原因是什么? URL在浏览器中工作时出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NodeJS训练myslef,并尝试了一个简单的GET调用. 这是我的代码:

I train myslef with NodeJS and tried a simple GET call. Here is my code:

var http = require('http');

var options = {
    host: 'www.boardgamegeek.com',
    path: '/xmlapi/boardgame/1?stats=1',
    method: 'GET'
}

var request = http.request(options, function (response) {
    var str = ""
    response.on('data', function (data) {
        str += data;
    });
    response.on('end', function () {
        console.log(str);
    });
});

request.on('error', function (e) {
    console.log('Problem with request: ' + e.message);
});

request.end();

所调用的URL似乎在我的浏览器中有效 https://www.boardgamegeek .com/xmlapi/boardgame/1?stats = 1

The URL called seems to work in my browser https://www.boardgamegeek.com/xmlapi/boardgame/1?stats=1

无论如何,我遇到了请求问题:运行代码并且不知道如何解决该问题时,请连接ETIMEDOUT .

什么可能导致此错误?是我的代码还是网络/代理问题?

What could cause this error ? Is it my code or is it a network/proxy issue?

推荐答案

在代理之后,您需要进行以下修改(如

When behind a proxy you need to make the following modifications (as explained in this answer):

  • 将代理主机放入host参数
  • 将代理端口放入port参数
  • 将完整的目标URL放入path参数:
  • put the proxy host in the host parameter
  • put the proxy port in the port parameter
  • put the full destination URL in the path parameter :

哪个给:

var options = {
    host: '<PROXY_HOST>',
    port: '<PROXY_PORT>',
    path: 'http://www.boardgamegeek.com/xmlapi/boardgame/1?stats=1',
    method: 'GET',
    headers: {
        Host: 'www.boardgamegeek.com'
    }
}

这篇关于可能导致“连接超时"的原因是什么? URL在浏览器中工作时出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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