2016-07-08 15 views
0

使用請求TCP時總是REST,但使用節點native http模塊是好的。NodeJS請求拋出[Error:read ECONNRESET]使http調用時

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 

}) 

如何修復它?

+0

這可能會幫助 - http://stackoverflow.com/questions/17245881/node-js-econnreset – Chinni

+0

但它不是我的網站,我只是試圖抓取conent – user6564357

回答

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

此網站標題'主機'必須是首字母縮寫。

HTTP模塊使用「主機」爲默認值,但請求模塊使用「主機」