Server 415 Response code
Asked Answered
F

2

16

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?

Franz answered 2/1, 2012 at 10:50 Comment(0)
A
30

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.

Anadiplosis answered 5/1, 2012 at 8:28 Comment(0)
M
0

If you're using axios, and making;

a) A post request, you should define the request as below

await axios.post("the url you're speaking to",
     {the data to post}, 
     {
        headers: {"Content-Type": "application/json"}
     })

b) A get request;

await axios.get("the url you're speaking to",
     {
        data: {},
        headers: {"Content-Type": "application/json"},
        params: {'varX': '34'}
     })

where varX is the name of the variable you're sending together with the request params can as well be empty if you're not sending a query string along.

the url would therefore appear as;

https://myurl.com/?varX=34 
Moseley answered 9/5, 2021 at 16:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.