0

I have been trying to send GET requests to a web server through public proxy servers. But not sure how to pass GET path to the proxy.

I tried to pass path parameter in options as well as in Host header as well. It's not working anyhow. Here's what I've tried so far.

var proxy = { ip: '121.12.1.1', port: 3128 };    
var options = {
    uri: 'http://' + proxy.ip + ':' + proxy.port,
    method: 'GET',
    path: '/json',
    headers: {
        'Host': 'http://wtfismyip.com/json'
    }
};

request(options, function (error, response, body) {

    if (!error && response && (response.statusCode == 200 || response.statusCode == 302 ) ) {
        console.log("success proxy response: ", response && response.statusCode, body);
    }
    else {
        console.log("error in proxy response: ", err, response && response.statusCode);
    }
})

But its only calling http://wtfismyip.com/. So, how do I call http://wtfismyip.com/json through the proxy server?

Haywire
  • 858
  • 3
  • 14
  • 30

1 Answers1

0

Look at the following Stack Overflow post.

You simply have to change your options to be

var options = {
   proxy: 'http://' + proxy.ip + ':' + proxy.port,
   method: 'GET',
   url: 'http://wtfismyip.com/json',
};
Community
  • 1
  • 1
  • Specifically it throws `{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' } ` with this method. – Haywire Jun 19 '15 at 03:55
  • It might be a problem with the proxy you are using. I tried a few in [this list](http://proxylist.hidemyass.com/). It's true some do work, some don't. – Mathieu Gardere Jun 21 '15 at 06:10