why it shows statuscode 415 error in axios get method?

ぃ、小莉子 提交于 2021-01-29 13:13:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!