I have a problem with my web service.
GET
requests are executed well and correct but the post request is getting the HTTP Status 415.
The project I am working on is a JAX-RS RESTful API that will need to communicate with an Android mobile application. I can receive the information from the GET
statement.
This is the code of my LoginFormat
object:
@XmlRootElement
public class LoginFormat {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Here you can see the POST
sample of my CoCreationService
class:
@Path("/User")
public class CoCreationService {
@POST
@Path("/testLogin")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response parseTerm(LoginFormat login) {
return Response.status(200).entity(login.getUsername() + login.getPassword()).build();
}
}
I tried so much that I am confused from it.
I was testing the web service wit curl:
curl -i -X POST -H 'Content-Type: application/json' -d '{"username": "testuser", "password": "test"}' http://localhost:8080/CoCreationService/api/User/testLogin
Is there some setting that needs to be said or did I make a crucial mistake?
PS: I am working with NetBeans.
Edit: A POST with text/plain works!
@POST
@Path("/testPost")
@Consumes("text/plain")
public Response postClichedMessage(String message) {
return Response.status(200).entity(message).build();
}