我在使用 Content-type: 'application/x-www-form-urlencoded'
在 node.js 中发布数据时遇到问题
var loginArgs = {
data: 'username="xyzzzzz"&"password="abc12345#"',
//data: {
// 'username': "xyzzzzz",
// 'password': "abc12345#",
//},
headers: {
'User-Agent': 'MYAPI',
'Accept': 'application/json',
'Content-Type':'application/x-www-form-urlencoded'
}
};
发布请求是:
client.post("http:/url/rest/login", loginArgs, function(data, response){
console.log(loginArgs);
if (response.statusCode == 200) {
console.log('succesfully logged in, session:', data.msg);
}
它总是返回 用户名/密码 不正确。
在其余 api 中,据说请求正文应该是:
username='provide user name in url encoded
format'&password= "provide password in url encoded format'
原文由 rahul 发布,翻译遵循 CC BY-SA 4.0 许可协议
request
支持application/x-www-form-urlencoded
和multipart/form-data
表单上传。对于multipart/related
参考多部分 API。application/x-www-form-urlencoded(URL 编码表单)
URL 编码的表单很简单:
见: https ://github.com/request/request#forms
或者,使用
request-promise
请参阅: https ://github.com/request/request-promise#api-in-detail