Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What could cause "connect ETIMEDOUT" error when the URL is working in browser?

Tags:

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();

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

Anyway, I've got Problem with request: connect ETIMEDOUT when I run the code and I have no idea how to fix it.

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

like image 961
Alex Avatar asked Oct 26 '15 16:10

Alex


1 Answers

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

  • 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 :

Which gives:

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'
    }
}
like image 54
sdabet Avatar answered Sep 17 '22 02:09

sdabet