用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();
请大侠帮帮忙,如何解决。