【发布时间】:2024-01-24 11:06:01
【问题描述】:
我正在通过 axios 从 react 客户端发出 post 请求。发布请求是微软自定义翻译器 api。由于某种原因,我不断收到 400 错误。
当我检查 chrome 的网络选项卡下的错误响应时,我看到了这个错误 => {"code":400074,"message":"The body of the request is not valid JSON."}
这个帖子请求与邮递员完美配合。我在这里错过了什么?
let config = {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '<valid-key>',
},
params: {
'api-version': '3.0',
'to': 'de',
'category': '<valid-category-id>'
}
}
let data = {
"body" : [
{"Text": "Hello"}
]
}
axios.post('https://api.cognitive.microsofttranslator.com/translate/', data, config)
.then((res) => console.log(res))
.catch((err) => console.log(err));
【问题讨论】:
标签: json reactjs post axios microsoft-translator