I\'ve managed to make changes to everything but the following:
HttpClient client;
HttpPost method;
client = new DefaultHttpClient();
method = new HttpPost(url
Use EntityUtils
and check the returned entity to be not null
before consuming the entity:
InputStream rstream;
try {
HttpResponse response = client.execute(HttpHost, method);
rstream = Optional.ofNullable(httpResponse.getEntity())
.map(e -> response.getContent()).orElse(null);
} catch (IOException e) {
return BadSpot(e.getMessage());
}
NOTE: the InputStream here can be null and most of all you have to ensure that it's consumed before you actually close the response/release the connection.