Reputation: 5840
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?
Upvotes: 16
Views: 47416
Reputation: 1012
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
Upvotes: 0
Reputation: 10154
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
.
Upvotes: 30