-1

I am trying to run the following node code,

function getQuestions() {
    var options = {
        host: 'mysite.com',
        path: '/services/v2/question.json',
        headers: {
            "Content-Type": "application/json",
            "accept": "application/json; charset=UTF-8",
            'Authorization': auth
        }
    };
    http.request(options, function(response) {
        console.log("Everything worked!");
    }).on('error', function(e) {
        console.log('problem with request: ' + e.stack);
    });
}

But it always errors saying...

problem with request: Error: connect ECONNREFUSED
    at errnoException (net.js:905:11)
    at Object.afterConnect [as oncomplete] (net.js:896:19)

When I put the same info into Postman it works fine. Is there a way to debug this?

Update

Tried this...

var options = {
        host: "google.com"
};

Same result so something must be wrong in my code. Any ideas?

Jackie
  • 21,969
  • 32
  • 147
  • 289
  • What is `auth`? What is the HTTP response? – Ram Aug 17 '15 at 19:40
  • Of course I can't post Auth but it is just basic auth. I copied the exact text to postman and it works fine. I don't think that is the issue because the google example has no auth. Could be proxy or some such but I have no idea how to debug – Jackie Aug 17 '15 at 19:42
  • Does this answer your question? [How can I use an http proxy with node.js http.Client?](https://stackoverflow.com/questions/3862813/how-can-i-use-an-http-proxy-with-node-js-http-client) – Ian Kemp Sep 04 '20 at 12:18

1 Answers1

0

It did end up being a proxy issue this...

var options = {
    host: "proxy",
    port: 80,
    path: 'http://google.com'
};

Notice the proxy in host. I will mark as duplicate of this post

Community
  • 1
  • 1
Jackie
  • 21,969
  • 32
  • 147
  • 289