前端使用的封装的 axios请求,后端java
出现上面的问题是因为前后端数据格式不统一。
json 分为两种类型;
(1) json 对象类型,即前端定义的Content type 为 application/x-www-form-urlencoded等
(2) json字符串类型,即前端定义的Content type 为 application/json
打印一下put
console.log(instance.defaults.headers.put)
很显然,put默认的Content type 是第一种
所以,解决这个问题,设置默认put的content-type 为application/json; charset=UTF-8,与后端保持一致即可。
import axios from 'axios';
const instance = axios.create({});
instance.defaults.headers.put['Content-Type'] = 'application/json; charset=UTF-8';