I am using Jetty web server, and Jersey for REST handling.
I defined:
@POST
@Path("/sendMessage")
@Consumes ({MediaType.APPLICATION_XML, MediaType.TEXT_XML})
public Response sendMessage(@Context final UriInfo uriInfo)
{
logger.debug("sendMessage:");
System.out.println("Received POST!");
return Response.status(Response.Status.OK).build();
}
However, when I send a http request, http://localhost:8080/hqsim/sendMessage
, the server returns a 415 code.
It's like the call is not allowed. How can I fix this 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.
Http 415 Media Unsupported is responded back only when the content type header you are providing is not supported by the application. With POSTMAN, the Content-type header you are sending is Content type 'multipart/form-data not application/json .
To do this, open Postman and create a new request by selecting New->Request from the top left: Under Headers, select Key = Content-Type: For Value, select application/json: THANKS FOR READING.
415 means that the media type is unsupported.
The most likely case is that you are either missing the Content-Type
header in your request, or it's incorrect. In your case it must be application/xml
or text/xml
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With