所以,我正在尝试向 api 发出请求,当我在我的节点项目上使用 Axios 执行此操作时,它返回 422,当我在邮递员上使用相同的标头和相同的数据执行相同的请求时或迅雷客户端,他们给我200和我需要的数据。我对这条特定路线有疑问。
const config = () => {
return {
headers: {
Authorization: `Bearer ${process.env.TOKEN}`,
Accept: 'application/json',
'User-Agent': `Aplicação (${process.env.CONTACT_EMAIL})`
}
}
}
router.post('/calculate', async (req, res) => {
const resp = await Axios.post(`${process.env.ENDPOINT}/api/v2/me/shipment/calculate`, req.body, config())
return res.status(200).send(resp.data);
})
请求正文:
{
"from": {
"postal_code": "96020360"
},
"to": {
"postal_code": "01018020"
},
"products": [
{
"id": "x",
"width": 11,
"height": 17,
"length": 11,
"weight": 0.3,
"insurance_value": 10.1,
"quantity": 1
},
{
"id": "y",
"width": 16,
"height": 25,
"length": 11,
"weight": 0.3,
"insurance_value": 55.05,
"quantity": 2
},
{
"id": "z",
"width": 22,
"height": 30,
"length": 11,
"weight": 1,
"insurance_value": 30,
"quantity": 1
}
]
}