Reputation: 647
I'm trying to connect via proxy in nodeJs, but I don't have any result or error.
I'm using mikeal/request
.
I've tested proxy in the command line and it works properly:
$ http_proxy=localhost:9060 wget http://wtfismyip.com/json
$ cat json
returns
{
"YourFuckingIPAddress" : "62.236.108.73",
"YourFuckingLocation" : "Finland",
"YourFuckingHostname" : "effi.org",
"YourFuckingISP" : "TDC Oy Finland"
}
As expected. But my request in 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});
}
}
);
});
log invalid protocol error:
error: [Error: Invalid protocol: http]
Does anyone know how to fix it? Do anyone have working example with proxy in mikeal/request & nodejs?
Upvotes: 3
Views: 12715
Reputation: 647
Fixed it!
I've replaced proxy object with string & it works:
proxy: 'http://localhost:9060',
Upvotes: 3