![](/img/trans.png)
[英]Why i'm getting a network error, when trying to send a post request using axios
[英]Getting error when using axios POST
我的網址、標題和正文數據定義為:
var headers = {
'Authorization': 'Bearer 12345',
'Content-Type': 'application/x-www-form-urlencoded'
}
var data = {
'password': '123456',
'ver': '1',
'time': '1534494857045'
}
我通過以下方式調用axios
:
axios.post(url, data, headers)
.then(response => {
console.log(response);
})
.catch(error => {
if (error.response) {
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
console.log(error.request);
} else {
console.log('Error', error.message);
}
console.log(error.config);
});
我從服務器收到500
錯誤。 調用同一服務器的其他應用程序工作正常。 我什至在 Postman 中嘗試過這個,它有效。 我在axios
做錯了axios
?
遺憾的是,這是一個有根據的猜測,因為沒有提供 MCVE。
請參閱 axios 的文檔:
默認情況下,axios 將 JavaScript 對象序列化為 JSON。 要改為以 application/x-www-form-urlencoded 格式發送數據,您可以使用以下選項之一。
您正在設置一個Content-Type
標頭,該標頭聲稱您正在發送application/x-www-form-urlencoded
數據,但您尚未執行文檔建議的以該格式生成數據的任何操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.