I know that GET call should not have body but the call is developed by other people and I can't change it now. I want to consume an API which is GET method and takes payload (json body). I can consume a GET method passing path param but not payload. I don't see an option to send payload for GET call.
Here is the GET call I am doing.
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
Client client = ClientBuilder.newClient();
String targetUri = "http://" + service.getHost() + ":" + service.getPort() + PROFILES_URI;
Response response = client
.target(target)
.path(profileIds.get(0))
.request(MediaType.APPLICATION_JSON)
.get();
If the method is PUT or POST I can send the payload as shown below.
Client client = ClientBuilder.newClient();
String target = "http://" + service.getHost() + ":" + service.getPort() + PROFILES_URI;
Response response = client
.target(target)
.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(profileIds, MediaType.APPLICATION_JSON));
How do I send payload with GET call?
Reference: http://www.baeldung.com/jersey-jax-rs-client