https.request 出现异常[Error: connect ECONNREFUSED]
用https.request模拟post请求出现异常:
{ [Error: connect ECONNREFUSED],code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }
代码如下:
var https=require("https");
var querystring=require("querystring");
var contents=querystring.stringify({
password:"1213mzl",
identity:"15989492323",
token:"1cb42f5d9df6f9d468ffb755723149c1"
});
var options={
host:"shenzhen.baixing.com",
path:"/oz/login/x",
method:"post",
headers:{
"Content-Type":"application/x-www-form-urlencoded",
"Content-Length":contents.length,
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language":"zh-CN,zh;q=0.8,en;q=0.6",
"Cache-Control":"max-age=0",
"Connection":"keep-alive",
"Host":"shenzhen.baixing.com",
"Referer":"http://shenzhen.baixing.com/oz/login/x",
"User-Agent":"Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko)"
}
};
var request=https.request(options,function(res){
res.setEncoding("utf8");
res.on("data",function(data){
console.log("data:"+data);
});
});
request.on('error', function (err) {
console.log(err);
});
request.write(contents);
request.end();
请大侠帮帮忙,如何解决。
4 回复
人家做了防爬?
ECONNREFUSED 一般是 TCP 握手都没成功,如果第一次就是这样,可能是你地址或者端口填错了;如果一段时间之后变成这样,有可能是你被对方封掉了。
tcpdump看下流程
连接被丢弃了.