HttpClient 4.0.1 - how to release connection? [duplicate]
The recommended way, by Httpcomponents 4.1, is to close connection and release any underlying resources:
EntityUtils.consume(HttpEntity)
where HttpEntity
passed is a response entity.
This seems to work great :
if( response.getEntity() != null ) { response.getEntity().consumeContent(); }//if
And don't forget to consume the entity even if you didn't open its content. For instance, you expect a HTTP_OK status from the response and don't get it, you still have to consume the entity !
To answer my own question: to release the connection (and any other resources associated with the request) you must close the InputStream returned by the HttpEntity:
InputStream is = entity.getContent();.... process the input stream ....is.close(); // releases all resources
From the docs