我正在尝试学习node.js,并且正在开发一个用于登录网站并提取一些信息的实用工具。在文档中,我读到重定向应该会"自动工作",但我无法使其正常工作。
request({
url: start_url,
method: 'POST',
jar: true,
form: {
action: 'login',
usertype: '2',
ssusername: '****',
sspassword: '****',
button: 'Logga in'
}
}, function(error, response, body) {
if (error) {
console.log(error);
} else {
console.log(body, response.statusCode);
request(response.headers['location'], function(error, response, html) {
console.log(html);
});
}
});
首先,我进行POST操作,得到了response.statusCode == 302的响应。但是,正文为空。我预期正文中会包含被重定向的页面。
然后我在response.headers['location']中找到了“新”的url。使用该url时,正文只包含一个“未登录”页面,而不是我预期的页面。
有人知道如何解决这个问题吗?