可能是由于axios的默认Content-Type头与服务器预期的不同所导致的问题。在axios请求中,将Content-Type的值更改为'application/x-www-form-urlencoded”或'multipart/form-data”,或者在请求头中添加一个Accept头,以告知服务器接受何种类型的内容。以下是一些示例代码:
修改Content-Type头的值:
axios.post('/api/post', {
name: 'John Doe',
age: 26
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
添加Accept头:
axios.post('/api/post', {
name: 'John Doe',
age: 26
}, {
headers: {
'Accept': 'application/json'
}
})