Getting an error while trying to consume a Restful web service using POST method(with form param).
I want to consume a REST application using POST method. Please find below the resource class I want to access.
@Path("/user")
public class User {
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response get(@FormParam("username") String userName,
@FormParam("userid") String userId ){
}
I tried using Jesry Client for accessing.Please find below the code i tried. I tried adding values to FormParam as shown below.
Trail 1
WebResource webResource = client.resource("baseURL/user");
String input = "userid:1001,username:demo1";
ClientResponse response = webResource.type("application/x-www-form-urlencoded").post(ClientResponse.class, input);
I am getting a an error response back "The server encountered an internal error () that prevented it from fulfilling this request". I think I am not adding the values to FormParam properly.
Trial 2
I also tried adding the form params using the below code
MultivaluedMap formData = new MultivaluedMapImpl();
formData.add("userid", "1001");
formData.add("username", "demo1");
ClientResponse response = webResource.type("application/x-www-form-urlencoded").post(ClientResponse.class, formData);
This also resulted in the same error.
Trial 3
Form f = new Form();
f.add("userid", "1001D");
f.add("username", "1001D");
ClientResponse response = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, f);
This also resulted in the same error. Any help is appreciated.