6

I'm trying to figure how how to use the Jersey client to send both the request params and the request body of a POST operation.

Currently I know how to do it both of those way individually, but not together.

From here: Using the Jersey client to do a POST operation

I've gotten this for the request parms:

MultivaluedMap formData = new MultivaluedMapImpl();
formData.add("name1", "val1");
formData.add("name2", "val2");
ClientResponse response = webResource.type("application/x-www-form-urlencoded").post(ClientResponse.class, formData);

And for the request body I can do the following:

String jsonObject ="... valid json object";
webResource.type(MediaType.APPLICATION_JSON_TYPE).post(String.class, jsonObject);

How do I post both a request param with a request body?

Thanks

Community
  • 1
  • 1
technocrat
  • 3,513
  • 5
  • 25
  • 39

1 Answers1

9

I just figured it out..

webResource.queryParam("key", "value").type(MediaType.APPLICATION_JSON_TYPE).post(String.class, jsonObject);
technocrat
  • 3,513
  • 5
  • 25
  • 39
  • 2
    rats, just as I was about to post that: http://jersey.java.net/nonav/apidocs/1.4/jersey/com/sun/jersey/api/client/WebResource.html#queryParams(javax.ws.rs.core.MultivaluedMap) – Jamie McCrindle Jan 24 '12 at 20:10