var req ={
"request": {
"header": {
"username": "name",
"password": "password"
},
"body": {
"shape":"round"
}
}
};
request.post(
{url:'posturl',
body: JSON.stringify(req),
headers: { "content-type": "application/x-www-form-urlencoded"}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
我希望将原始请求主体发送到req变量中。在Postman上可以工作,但在Node.js中,我无法将原始JSON作为POST请求的请求主体发送。
"content-type": "application/x-www-form-urlencoded"
可能不正确,因为你正在发送 JSON。它应该是application/json
。 - Kelly Keller-Heikkila