javascript - GET Request in node.js is not working -
i'm having big troubles loading page through node.js. code of node.js application, please note works if try load other resources (like www.google.com) question specific domain name www.egopay.com:
var http = require('http'); var options = { hostname: 'www.egopay.com', port: 80, path: '/', method: 'get' }; var req = http.request(options, function(res) { console.log('status: ' + res.statuscode); console.log('headers: ' + json.stringify(res.headers)); res.setencoding('utf8'); res.on('data', function (chunk) { console.log('body: ' + chunk); }); }); req.on('error', function(e) { console.log('problem request: ' + e.message); }); // write data request body req.write('data\n'); req.write('data\n'); req.end();
using curl works, node.js won't.
around 1 minute after request error shows up:
problem request: read econnreset
when made same request, added user-agent headers, got response, made clear happening. try adding line options:
headers: {'user-agent': 'mozilla/5.0 (macintosh; intel mac os x 10_8_4) applewebkit/537.36 (khtml, gecko) chrome/29.0.1547.62 safari/537.36'},
basically, have nginx server redirects https site same url. not getting response without including user agent bug in nginx deployment site. can explain no other way, cannot recreate circumstances in chrome or firefox. when overriding empty user-agent. imagine difference between empty string , undefined string. node sending header's field undefined, whereas browsers i'm trying replicate sending empty string. again, can't recreate, best guess.
Comments
Post a Comment