新手小白求助 request 问题

2018-10-12 16:58:27 +08:00
 xxxwyp
request({
url:"https://gzmss.iok.la/api/v2/users/signin",
method: 'POST',
headers: {
"content-type": "application/json",
},
// body: JSON.stringify(userObj),
body:{'password':"123456",
'user_name':"yeungy"
},
json: true
},function(error,response,body){
console.log(body);
})

为什么这段代码会报 400 错误,用 postman 能通,通过 node 请求不行
2564 次点击
所在节点    Node.js
3 条回复
xxxwyp
2018-10-12 16:59:30 +08:00
在线等,期待大神稍微抽点时间帮忙解决,抽感激不尽!
Debiancc
2018-10-15 09:41:47 +08:00
400 错误贴一下
liliya
2018-10-15 13:45:52 +08:00
var request = require("request");

var options = { method: 'POST',
url: 'https://gzmss.iok.la/api/v2/users/signin',
headers:
{
'content-type': 'application/x-www-form-urlencoded' },
form: { user_name: 'yeungy', password: '123456' } };

request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/497123

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX