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

后端 未结 6 1436
深忆病人
深忆病人 2021-02-19 07:46

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\',
             


        
6条回答
  •  无人及你
    2021-02-19 08:12

    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: '',
        port: '',
        path: 'http://www.boardgamegeek.com/xmlapi/boardgame/1?stats=1',
        method: 'GET',
        headers: {
            Host: 'www.boardgamegeek.com'
        }
    }
    

提交回复
热议问题