Saturday, 29 April 2017

ECONNRREFUSED Error when making a get request to an API with Nodejs

I did make a get request to an API but get an ECONNREFUSED Error. The problem is not the API because when I type it in a browser, I get back results in JSON.

This is my code;

var https = require("https");

var options = {
    host :  'nairabox.com',
    port : 443,
    path : '/v1/tickets/auth=APIKEY&as=showtimes&cinemaId=CINEMAID&ticketId=TICKETID',
    method : 'GET'
}


var req = https.request(options, function(res) {
  res.on('data', function(data) {
      console.log( JSON.parse(data));
  });
});

req.end();

req.on('error', function(err){
    console.log("Error: ", err);
}); 

This is the error;

Error:  { Error: connect ECONNREFUSED 162.255.119.75:443
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '162.255.119.75',
  port: 443 }

Anyone can be kind enough to test it replacing the parameters with random numbers and you'd get the same error. How can I fix it. API gives results in the browser though.



via beanseasy

No comments:

Post a Comment