Curl POST no pasa los parámetros de URL
Este es mi código java:
@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";
}
Lo llamo así:
curl -XPOST "http://localhost:8080/CurlServer/curl/curltutorial/sumPost" -d 'x:5&y:3'
El problema es elSystem.out.println
La llamada sigue publicando cero cero, parece que no estoy pasando x e y correctamente.
Después de la respuesta, cambié mi solicitud a:
curl -d '{"x" : 4, "y":3}' "http://localhost:8080/CurlServer/curl/curltutorial/sumPost" -H "Content-Type:application/json" -H "Accept:text/plain" --include
y el servicio es:
@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";
}
Pero todavía tengo el mismo problema. Aquí está la respuesta del servidor:
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
Puedes ver el cero al final :(