我是node.js的新手,我正尝试向外部服务器(Oracle Commmerce Cloud)发出发布请求以导出一些数据。 Postman中请求正文的PFA图像屏幕快照 (内容类型:application / json) Request Body In Postman
当我尝试使用node中的express发出相同的请求时,会抛出错误。我不确定是否还有其他方法可以在节点请求中编写邮递员的正文原始json。
下面是我的节点请求代码
let req_body = JSON.stringify({
"fileName": fileName,
"mode": mode,
"id": category,
"format": format
})
request.post(url, {
data :{req_body},
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${access_token}`
}
}, (error, res, body) => {
if (error) {
console.log('An error occured while loading the page', error)
// console.error(error)
return
}
console.log("export call:", res.statusCode)
console.log("export call:", data)
});
我收到以下控制台错误:-
export call: 400
export call: {
errorCode: '120001',
message: 'Invalid export input data',
status: '400'
}
请帮助我解决这个问题。
答案 0 :(得分:0)
我将假设您正在使用request
节点模块,但是数据是通过body
参数而不是data
传递的,它看起来像这样:
request.post(url, {
body: req_body,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${access_token}`
}
}, (error, res, body) => {
if (error) {
console.log('An error occured while loading the page', error)
// console.error(error)
return
}
console.log("export call:", res.statusCode)
console.log("export call:", data)
});