I keep getting an HTTP 406 response when I try to execute code structured this way. I tried many times to rebuild the code and inputs, but I still get this error, and I realized that I donβt even know what to debug. The exception seems to indicate that the post() method does not provide @FormParam in the desired format, but as you can see .accept(MediaType.APPLICATION_FORM_URLENCODED) and @Consumes(MediaType.APPLICATION_FORM_URLENCODED) do match.
I am using the Firefox HTTPRequester add-in to transmit to @FormParam and ensure that I pass them using the appropriate Content-Type ( application/x-www-form-urlencoded ). I ran out of things to check. Does anyone have any ideas?
Proxy service
Client client = Client.create(); WebResource service = client.resource(myURL); Form form = new Form(); form.add("value1", value1); form.add("value2", value2); form.add("valueN", valueN); String returnValue = service.accept(MediaType.APPLICATION_FORM_URLENCODED).post(String.class, form);
Actual Service
@POST @Produces(MediaType.APPLICATION_XML) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/theService") public String theService( @FormParam("value1") String value1, @FormParam("value2") String value2, @FormParam("valueN") String valueN) { String returnValue = null; return returnValue; }
An exception
com.sun.jersey.api.client.UniformInterfaceException: POST http://theURL/theService returned a response status of 406 at com.sun.jersey.api.client.WebResource.handle(WebResource.java:563) at com.sun.jersey.api.client.WebResource.access$300(WebResource.java:69) at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:499)
source share