What can result in a “connect ETIMEDOUT” error when the url is running in the browser?

I train myslef using NodeJS and have 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();

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

In any case, I have a problem with the request: connect ETIMEDOUT when running the code, and I have no idea how to fix it.

What can cause this error? Is this my code or network / proxy problem?

+4
source share
1 answer

If you need to make the following changes behind the proxy server (as described in this answer ):

  • enter the proxy server in the parameter host
  • - port
  • URL path:

:

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'
    }
}
+3

Source: https://habr.com/ru/post/1613226/


All Articles