在vue2.0中使用了axios库,设置请求头Content-Type='application/json;charset=UTF-8'无效
axios.defaults.headers.common['Content-Type'] = 'application/json;charset=UTF-8'
还尝试了
http.get(http.api.url, {
params: params,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
})
也是没有起作用。
解决办法:
//use params instead of data
//用 params 代替 data
完整写法如下:
axios({
method: 'post',
url: '/my/api',
headers: {
'Content-type': 'application/json;charset=UTF-8'
},
params: {
'grant_type': 'code',
'client_id': '1231453',
'client_secret': 'THIS_IS_THE_SECRET'
}
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
}
);
https://www.leftso.com/article/497.html