Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting not supported media type error

Hi i am using Rest client i.e Postman to send the REST request but getting error :

{     "timestamp": 1432829209385,     "status": 415,     "error": "Unsupported Media Type",     "exception": "org.springframework.web.HttpMediaTypeNotSupportedException",     "message": "Content type 'text/plain;charset=UTF-8' not supported",     "path": "/api/v1/user" } 

My controller is :

@RequestMapping(value = "/user", method = RequestMethod.PUT, produces = "application/json")     public Map<String,Object> updateUser(@RequestBody @Valid User user) { //      userService.updateUser(user);         return ResponseHandler.generateResponse("", HttpStatus.ACCEPTED, false, null);     } 

I am sending the request as shown in picture via REST client.

enter image description here

like image 293
Qasim Avatar asked May 28 '15 16:05

Qasim


People also ask

How do I fix unsupported media type error?

Fixing 415 Unsupported Media Type errorsEnsure that you are sending the proper Content-Type header value. Verify that your server is able to process the value defined in the Content-Type header. Check the Accept header to verify what the server is actually willing to process.

How do you solve unsupported media type in Postman?

You need to set the content-type in postman as JSON (application/json). Go to the body inside your POST request, there you will find the raw option. Right next to it, there will be a drop down, select JSON (application. json).

How do I fix status 415?

The 415 Unsupported Media Type error code usually indicates that the request entity has a media type that the server or resource does not support. The best way to fix the error is to make sure that you are sending the right Content-Type header value.


1 Answers

Change your Content-Type in Postman to application/json. Click on the Headers button to do so.

Also you are not producing json in the method. Remove the produces="application/json" from the annotation

like image 90
kjsebastian Avatar answered Oct 14 '22 13:10

kjsebastian