在NodeJS中使用代理获得“无效协议”

我试图通过nodeJs代理连接,但我没有任何结果或错误。 我正在使用mikeal/request

我已经在命令行testing了代理,它正常工作:

 $ 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}); } } ); }); 

logging无效的协议错误:

  error: [Error: Invalid protocol: http] 

有谁知道如何修理它? 有没有人在mikeal / request&nodejs中使用代理工作示例?

修复!

我已经用stringreplace代理对象,它的工作原理:

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