I am actually new to REST WS but really I don\'t get this 415 Unsupported Media Type
.
I am testing my REST with Poster on Firefox and the GET
I had the same issue, as it was giving error-415-unsupported-media-type while hitting post call using json while i already had the
@Consumes(MediaType.APPLICATION_JSON)
and request headers as in my restful web service using Jersey 2.0+
Accept:application/json
Content-Type:application/json
I resolved this issue by adding following dependencies to my project
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25</version>
</dependency>
this will add following jars to your library :
I hope it will works for others too as it did for me.
If none of the solution worked and you are working with JAXB, then you need to annotate your class with @XmlRootElement
to avoid 415 unsupported media type
Just in case this is helpful to others, here's my anecdote:
I found this thread as a result of a problem I encountered while I was using Postman to send test data to my RESTEasy server, where- after a significant code change- I was getting nothing but 415 Unsupported Media Type errors.
Long story short, I tore everything out, eventually I tried to run the trivial file upload example I knew worked; it didn't. That's when I realized that the problem was with my Postman request. I normally don't send any special headers, but in a previous test I had added a "Content-Type": "application/json" header. OF COURSE, I was trying to upload "multipart/form-data." Removing it solved my issue.
Moral: Check your headers before you blow up your world. ;)
I get the same issue. In fact, the request didn't reach the jersey annoted method. I solved the problem with add the annotation: @Consumes(MediaType.APPLICATION_FORM_URLENCODED) The annotation @Consumes("/") don't work!
@Path("/"+PropertiesHabilitation.KEY_EstNouvelleGH)
@POST
//@Consumes("*/*")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void get__EstNouvelleGH( @Context HttpServletResponse response) {
...
}
Don't return Strings in your methods but Customer objects it self and let JAXB take care of the de/serialization.
In case you are trying to use ARC app from google and post a XML
and you are getting this error, then try changing the body content type to application/xml
. Example here