user6564357 user6564357 - 3 months ago 23
HTTP Question

NodeJS Request throw [Error: read ECONNRESET] when make http call

when use Request TCP always REST, but use node native http module is fine.

var request = require('request');
var http = require('http');

request.get('http://www.drcnet.com.cn/www/integrated/login.ashx',function(err, res,body){

console.log(err, res); // [Error: read ECONNRESET]

});

http.get('http://www.drcnet.com.cn/www/integrated/login.ashx', function(res) {

console.log(res.statusCode); // 200 all right

})


how to fixed it ?

Answer
request.get('http://www.drcnet.com.cn/www/integrated/login.ashx',
    {
        originalHostHeaderName: 'Host'
    },
    function(err, res,body){
        console.log(err, res); 
    }
);

this site header 'Host' must be Initials.