POST methods

The POST method sends a set of parameters as a unique encoded block respect to the GET that sends them declaring them in the URL. The preferred media types used are the APPLICATION_FORM_URLENCODED very similar to a string, MULTIPART_FORM_DATA used to send entire files to the server, and TEXT_PLAIN. Usually, the POST method is used together with an HTML form. See how call the multiplication of the calculator declared as POST method and media type APPLICATION_JSON:

...
Entity<List<Double>> valuesAsList = Entity.entity(asList(new Double[] { 4.5, 6.7 }), MediaType.APPLICATION_JSON);
response = target.request().post(valuesAsList);
value = response.readEntity(Double.class);
...

The client needs to send data as entities. The javax.ws.rs.client.Entity class resolves this problem. The entity lets you declare the media type too. An important thing in this case is to set the data as list. The array is not permitted as it's not permitted to declare a media type different by the declaration of the service:

@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public double multi(double... values) {
...

The @Consumes annotation establishes that only a JSON can be sent to the service.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.208