2014-09-29 25 views
2

我想通過nodeJs代理連接,但我沒有任何結果或錯誤。 我正在使用mikeal/request與NodeJS代理得到「無效的協議」

我在命令行測試代理和它工作正常:

$ http_proxy=localhost:9060 wget http://wtfismyip.com/json 
$ cat json 

回報

{ 
    "YourFuckingIPAddress" : "62.236.108.73", 
    "YourFuckingLocation" : "Finland", 
    "YourFuckingHostname" : "effi.org", 
    "YourFuckingISP" : "TDC Oy Finland" 
} 

正如預期的那樣。但我的要求的NodeJS:

router.route('/proxy-ip') 
    .get(function (req, res) { 

     var request_options = { 
      url: 'http://wtfismyip.com/json', 
      proxy: { 
       host: "http://localhost", 
       port: 9060 
      } 
     }; 

     console.log({request:request_options}); 

     request.get(request_options, 
      function (error, response, json) { 
       if (!error && response.statusCode == 200) { 
        res.send(json); 
       } else { 
        console.log({'request': request, 'response': response, 'error': error, 'json': json}); 
        res.send({'response': response, 'error': error, 'json': json}); 
       } 
      } 
     ); 

    }); 

日誌無效協議錯誤:

error: [Error: Invalid protocol: http] 

有誰知道如何解決它?有沒有人在mikeal /請求& nodejs中使用代理工作示例?

回答

2

修好了!用繩子&

我已經更換了代理對象它的工作原理:

  proxy: 'http://localhost:9060',