Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http 415 Unsupported Media type error with JSON

Not sure about the reason but Removing lines charset=utf8 from con.setRequestProperty("Content-Type", "application/json; charset=utf8") resolved the issue.


Add Content-Type: application/json and Accept: application/json


If you are making jquery ajax request, dont forget to add

contentType:'application/json'

This is because charset=utf8 should be without a space after application/json. That will work fine. Use it like application/json;charset=utf-8


If you are using AJAX jQuery Request this is a must to apply. If not it will throw you 415 Error.

dataType: "json",
contentType:'application/json'

If you get this in React RSAA middleware or similar, Add the headers:

  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(model),