问题
While fetching API data using axios get method, it returns an error showing
statuscode 415(Unsupported Media Type)
I'm getting the expected result in postman.
This request needs raw data (username) in order to fetch specified data.
axios
.get(URL,{
username:"Name",
headers:{
'Content-Type': 'application/json;'
}
})
回答1:
Change to
axios.post(URL,{data:{ username:"Name"}, headers:{
'Content-Type': 'application/json;' } })
回答2:
The error 415 is given by the server when the payload you are passing is rejected and most probably because of wrong values or the format of data you have given.
// GET request
axios({
method: 'get',
url: 'URL',
responseType: 'application/json',
data:{ //your data }
})
来源:https://stackoverflow.com/questions/58375880/why-it-shows-statuscode-415-error-in-axios-get-method