Generally speaking, HTTP POST assumes that the contents of the body contain a series of key / value pairs that are created (most often) by the form on the HTML side. You do not set values ββwith setHeader, as this does not put them in the body of the content.
So, with your second test, the problem you are facing is that your client does not create several key / value pairs, it only creates one and which by default was matched with the first argument in your method.
There are several options you can use. First, you can change your method to accept only one input parameter, and then pass a JSON string, as in the second test. Inside the method, you then parse the JSON string into an object that allows access to the fields.
Another option is to define a class representing the fields of the input types, and make this the only input parameter. for example
class MyInput { String str1; String str2; public MyInput() { } // getters, setters } @POST @Consumes({"application/json"}) @Path("create/") public void create(MyInput in){ System.out.println("value 1 = " + in.getStr1()); System.out.println("value 2 = " + in.getStr2()); }
Depending on the REST structure used, it should handle JSON de-serialization for you.
The final option is to build a POST body that looks like this:
str1=value1&str2=value2
then add additional annotations to your server-side method:
public void create(@QueryParam("str1") String str1, @QueryParam("str2") String str2)
@QueryParam does not matter if the field is in the form message or in the URL (for example, in a GET request).
If you want to continue using individual arguments in the input, then the key generates a client request to provide named request parameters either in the URL (for GET) or in the body of the POST.