我正在尝试登录网站以废弃数据。如果尝试通过Chrome Rest Client
进行登录,则可以正常登录,但是从节点服务器我可以从网站获取status code 302
。代码
var http = require('http'),
express = require('express'),
request = require('request');
var app = express();
app.listen(3000);
var request = request.defaults({jar:true});
app.post('/login', [express.urlencoded(), express.json()], function(req, res) {
console.log('You are here'); console.log(JSON.stringify(req.body.email));
request.post({
url: 'http://teeSpring.com/login/submitLogin',
form: {
email: "himanshu",
password: "himanshu"
}
}, function(error, resposne, body) {
if (error) {
console.log('Error is: '+JSON.stringify(error));
} else if(body){
console.log('Body is :')//+JSON.stringify(body));
} else if(resposne) {
console.log('Response is :'+resposne.statusCode);//+JSON.stringify(resposne));
res.send(resposne);
} else {
console.log('WTF');
}
});
});
答案 0 :(得分:1)
你可以这样做 - 如果重定向,获取标题位置并去那里:
else if(response) {
console.log('Response is :'+response.statusCode);//+JSON.stringify(response));
if(response.statusCode == 302 && response.headers && response.headers.location) {
res.send(response.headers.location);
}
}