axios踩坑记录-post请求,参数放在body中时,报错Content type
在axios请求时,若不指定Content-Type,在axios内部,会自行更改,我们一般使用的是application/json但有时我们的数据格式并不一定是json,而后端配置的参数类型使用了注解@RequestBody,这时一定会报错,因为两者的类型不匹配.此时,我们需要手动设置Content-Typeaxios.post(baseURL,data,{headers: {'Cont...
·
报错信息:
Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
在axios请求时,若不指定Content-Type
,在axios内部,会自行更改,我们一般使用的是application/json
但有时我们的数据格式并不一定是json,而后端配置的参数类型使用了注解@RequestBody
,这时一定会报错,因为两者的类型不匹配.
此时,我们需要手动设置Content-Type
axios.post(baseURL,data,
{headers: {'Content-Type': 'application/json'}}
).then(result => {
})
这样就能解决问题了
更多推荐
已为社区贡献2条内容
所有评论(0)