POST 调用在 postman 中工作正常,但在 node.js 中出错

POST call is working fine in postman but gives error in node.js

我是 node.js 的新手,我正在尝试向外部服务器 (Oracle Commmerce Cloud) 发出 post 请求以导出一些数据。 Postman 中请求正文的 PFA 图片截图 (内容类型:application/json) Request Body In Postman

当我尝试在节点中使用 express 发出相同的请求时,它会抛出错误。我不确定是否有其他方法可以在节点请求中写入 postman 的 body raw 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'
}

请帮我解决这个问题。

我假设您正在使用 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)
});