node.js - ECONNREFUSED error https.request -


i trying download or file on remote https server. following error every time while other urls working.

{ [error: connect econnrefused]                                                                                                                                                                                                                                                                                              code: 'econnrefused',                                                                                                                                                                                                                                                                                                      errno: 'econnrefused',                                                                                                                                                                                                                                                                                                     syscall: 'connect' } 

i using code:

var https   = require('https'); var fs      = require('fs');  var url = '/portalfront/datafiles/miscellaneous/csv/kursliste_ws.xml'; //or:     '/portalfront/datafiles/miscellaneous/csv/kursliste.csv' var options = {   hostname  : 'dnb.no',   port      : 443,   path      : url,   method    : 'get' };  var req = https.request(options, function(res) {   console.log("statuscode: ", res.statuscode);   console.log("headers: ", res.headers);   res.on('data', function(d) {       process.stdout.write(d);   }); }); req.end();  req.on('error', function(e) {   console.error(e); }); 

i can fetch url postman.

to inspect request send browser can use build in inspector. in network card can see request data. requested file should there. if @ browser request headers, similar results this:

get /portalfront/datafiles/miscellaneous/csv/kursliste_ws.xml http/1.1 host: www.dnb.no connection: keep-alive cache-control: max-age=0 accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 upgrade-insecure-requests: 1 user-agent: mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, gecko) ubuntu chromium/45.0.2454.85 chrome/45.0.2454.85 safari/537.36 accept-encoding: gzip, deflate, sdch accept-language: en-us,en;q=0.8,pl;q=0.6 if-none-match: "5365-5604f43f" if-modified-since: fri, 25 sep 2015 07:14:07 gmt 

if closely see difference in host. change hostname from:

hostname  : 'dnb.no', 

to:

hostname  : 'www.dnb.no', 

now shold able retrieve xml file successfully.


Comments