"The media type in the POST request is not supported (415 error)"
P粉668019339
2023-08-25 12:30:41
<p>Does anyone know what causes error 415 (unsupported media type)? Thank you</p>
<pre class="brush:php;toolbar:false;">createArticleOld : async ({ commit, dispatch }, data) => {
let added = await dispatch('authorizedPostOld',
{ action: 'article',
data,
headers: {
'Content-Type': 'application/json-patch json',
'Accept': 'application/json-patch json',
},
}
)
console.log(added)
commit('ADD_ARTICLE', added)
},</pre></p>
Typically, HTTP response status code 415 tells you that the data you sent is in a format that the server does not accept, as briefly described here: here.
So to solve the problem you need to find out the format the server expects to receive the data in, and send it in that format. The easiest way is to check your server's documentation (or ask the developer).
If you examine the raw response returned by the browser (or perform the same request via a tool like cURL or Postman), you may find some clues there about the formats accepted by the endpoint or the specific issue causing the incorrect response.
Of course, this requires the developer of the server to implement HTTP status codes correctly, and they may have made a mistake. As a complete guess, given that you set the
Accept
header, the server is probably trying to tell you that it can't give you a response in the "application/json-patch json" format, although that should give you a 406 .