【发布时间】:2014-09-15 08:09:42
【问题描述】:
我正在尝试通过节点通过 POST 请求发送我的用户名和密码来对站点进行身份验证,因为登录表单似乎就是这样做的。使用Postman 进行尝试时,它工作得很好,我被重定向到我的仪表板。
遗憾的是,用户名和密码字段没有标记为用户名和密码,而是标记为 j_username 和 j_password。
这是邮递员给我看的数据(供参考):
POST /path/for/auth/request HTTP/1.1
Host: site.com
Cache-Control: no-cache
Postman-Token: b6656210-caeb-2b62-d6b6-e10e642b200b
Content-Type: application/x-www-form-urlencoded
j_username=myusername&j_password=mypassword
所以我在节点中尝试这个:
var request = require('request');
request.post({
headers: {'content-type' : 'application/x-www-form-urlencoded'},
url: 'https://site.com/path/for/auth/request',
body: "j_username=myusername&j_password=mypassword"
}, function(err, res, body){
console.log(body);
});
但不幸的是,它返回为空并且 err 设置为 null。
这里可能出了什么问题?或者有没有更好的方法来验证这个资源?据我所知,这里不可能通过标头告诉基本身份验证。
谢谢。
【问题讨论】:
标签: node.js authentication request