axios请求报错 415 unsupported media type
本地跑的项目,请求接口报415,postman和线上都是没问题的。
axios请求设置content Type不生效,有个默认值content-type: application/json;
这个参数改不掉。
回答:
话说前端现在都是处理json
,所以Content-Type: application/json;charset=UTF-8
完全没问题,我认为是接口的问题了,实在不行那就改header
吧
get 请求:
axios.get('https://example.com/getSomething', { headers: {
'Content-Type': 'xxxxxx'
}
})
post请求。
axios.post('https://example.com/postSomething', { email: varEmail, //varEmail is a variable which holds the email
password: varPassword
},
{
headers: {
'Content-Type': 'xxxxxx'
}
})
也可以设置这样的请求:
axios({ method: 'post', //you can set what request you want to be
url: 'https://example.com/request',
data: {id: varID},
headers: {
'Content-Type': 'xxxxxx'
}
})
以上是 axios请求报错 415 unsupported media type 的全部内容, 来源链接: utcz.com/p/935823.html