This is my java code:
@POST
@Path("/sumPost")
@Produces(MediaType.TEXT_PLAIN)
public String sumPost(@QueryParam(value = "x") int x,
@QueryParam(value = "y") int y) {
System.out.println("x = " + x);
System.out.println("y = " + y);
return (x + y) + "\n";
}
I call it like this:
curl -XPOST "http://localhost:8080/CurlServer/curl/curltutorial/sumPost" -d 'x:5&y:3'
The problem is the System.out.println
call keeps posting zero zero, it seems I am not passing x and y correctly.
Update
After the answer, I changed my request to:
curl -d '{"x" : 4, "y":3}' "http://localhost:8080/CurlServer/curl/curltutorial/sumPost" -H "Content-Type:application/json" -H "Accept:text/plain" --include
and the service is:
@POST
@Path("/sumPost")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
public String sumPost(@QueryParam(value = "x") int x,
@QueryParam(value = "y") int y) {
System.out.println("sumPost");
System.out.println("x = " + x);
System.out.println("y = " + y);
return (x + y) + "\n";
}
but I still have the same problem. Here is the response from the server:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/plain
Transfer-Encoding: chunked
Date: Wed, 23 Sep 2015 11:12:38 GMT
0
You can see the zero at the end :(