I am using the jersey client to send POST requests to a web server. I have generally been building up a Form object with key-value pairs. However, I now have to send a List within my request. Here's an abridged version of my code
// Phone is a POJO consisting of a few Strings
public void request(List<Phone> phones) {
Form form = new Form();
form.add("phones", phones);
ClientResponse response = WebService.getResponseFromServer(form);
String output = response.getEntity(String.class);
System.out.println(output);
}
public static ClientResponse getResponseFromServer(Form form) {
Client client = createClient();
WebResource webResource = client.resource(PATH);
return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, form);
}
Unfortunately, this doesn't seem to work, and I get a 400 bad request error. When I send a request directly
{"phones":[{"areaCode":"217","countryCode":"01","number":"3812565"}]}
I have no problems. Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire