我遇到的情况是,登录成功了,但是页面转向到别的页面就成了登录超时的页面,发送的时候,headers传了Cookie,结果是
{ [Error: socket hang up] code: 'ECONNRESET' }
。代码如下:
- 出现登录超时的代码:
https.get({
hostname:"mp.weixin.qq.com",
path: "/advanced/advanced?action=dev&t=advanced/dev&lang=zh_CN&token="+token
},function(res){
res.on('data', function(d) {
process.stdout.write(d);
});
});
- 出现error的代码:
var headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0",
"Host": "mp.weixin.qq.com",
"Connection": " keep-alive",
"Cache-Control":" max-age=0",
"Accept-Language": "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
"Accept-Encoding": "gzip, deflate",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"};
var options = {
hostname:"mp.weixin.qq.com",
path: "/advanced/advanced?action=dev&t=advanced/dev&lang=zh_CN&token="+token,
method: "GET",
headers: headers
};
options.headers["Referer"] = 'https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token='+token;
options.headers["Cookie"] = exports.cookie;
var html = '';
var req=https.request(options, function (res) {
res.on('data', function (d) {
process.stdout.write(d);
if(res.statusCode == 200){
//exports.beDev(token);
}
})
}).on('error', function (e) { console.error(e); });
req.end();
- 出现乱码的代码:
https.get({
hostname:"mp.weixin.qq.com",
path: "/advanced/advanced?action=dev&t=advanced/dev&lang=zh_CN&token="+token,
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0",
"Host": "mp.weixin.qq.com",
"Connection": " keep-alive",
"Cache-Control":" max-age=0",
"Accept-Language": "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
"Accept-Encoding": "gzip, deflate",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
'Referer': 'https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token='+token,
'Cookie': exports.cookie
}
},function(res){
res.on('data', function(d) {
process.stdout.write(d);
});
});
期待大神解答!!
3 回复