1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| private int sendJSON(String task, JSONObject jo) throws IOException
{
int status = 0;
HttpEntity stringEntity = new StringEntity(jo.toString(), ContentType.APPLICATION_JSON);
CloseableHttpClient httpclient = HttpClients.createDefault();
logger.info(task + "-> Create the POST to " + dest_server_url);
ClassicHttpRequest httpPost = ClassicRequestBuilder.post(dest_server_url).setEntity(stringEntity).build();
logger.info(task + " -> Execute the POST");
status = httpclient.execute(httpPost, response -> {
logger.info(task + " : " + response.getCode() + " " + response.getReasonPhrase());
final HttpEntity entity2 = response.getEntity();
// do something useful with the response body
// and ensure it is fully consumed
EntityUtils.consume(entity2);
return response.getCode();
});
httpclient.close();
return status;
} |
Partager