1

i am making a http call to a api and i am using 'request' module for this to work.

for example:

var request = require('request');
request.get("http://www.google.com",
        function (error, response, body){

        if(error){
            console.log(error);
        }
        else{
            console.log(response);
        }
    });

when i call this function i get an error, 'connect ECONNREFUSED'.

google is working on my browser but thru code i am not getting connected. can you please help me with this

Ritz Arlekar
  • 375
  • 1
  • 4
  • 20

1 Answers1

0

i found the solution for this. Actually i had to set proxy before making this call. For those people who are facing the same issue can try this:

var request = require('request');
var proxiedRequest = request.defaults({proxy: "http://yourProxy:8080"});

 var propertiesObject = { 'qs1':'qs1', 'qs2':'qs2'};

proxiedRequest({
url:'http://webaddress',
qs: propertiesObject,
method: 'GET'   
}, function (error, response, body){
        if(error){
            console.log(error);
        }
        else{
            console.log(response);
        }
    });

Hope it helps. :)

Ritz Arlekar
  • 375
  • 1
  • 4
  • 20