Michael Moeller
Michael Moeller

Reputation: 906

request http call over proxy server

Our server makes a http call without a proxy server. Is it possible to make the same call over a proxy server? (We would like to use request.)

example proxy server: 112.175.18.180 port 80

app.js:

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');



var request = require("request");

var parseMyAwesomeHtml = function(html) {
   console.log(html);
};

request("http://checkip.dyndns.org/", function (error, response, body) {
    if (!error)
        parseMyAwesomeHtml(body);
    else
        console.log(error);
});

Upvotes: 1

Views: 749

Answers (1)

Michael Moeller
Michael Moeller

Reputation: 906

We found the right syntax. Works great.

app.js:

var http = require('http');
var request = require("request");

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');


var parseMyAwesomeHtml = function(html) {
    console.log(html);
};



request({uri:"http://checkip.dyndns.org/",proxy: 'http://112.175.18.180/', port: 80 }, function (error, response, body) {
    if (!error)
        parseMyAwesomeHtml(body);
    else
        console.log(error);
});

Upvotes: 1

Related Questions