Example usage for org.apache.http.client.methods HttpGetWithEntity setEntity

List of usage examples for org.apache.http.client.methods HttpGetWithEntity setEntity

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpGetWithEntity setEntity.

Prototype

public void setEntity(final HttpEntity entity) 

Source Link

Usage

From source file:org.nuxeo.elasticsearch.http.readonly.HttpClient.java

public static String get(String url, String payload) throws IOException {
    if (payload == null) {
        return get(url);
    }/*from www. jav a  2 s  . c o m*/
    CloseableHttpClient client = HttpClients.createDefault();
    HttpGetWithEntity e = new HttpGetWithEntity(url);
    StringEntity myEntity = new StringEntity(payload,
            ContentType.create(MediaType.APPLICATION_FORM_URLENCODED, UTF8_CHARSET));
    e.setEntity(myEntity);
    try (CloseableHttpResponse response = client.execute(e)) {
        HttpEntity entity = response.getEntity();
        return entity != null ? EntityUtils.toString(entity) : null;
    }
}