I am using org.apache.http
and I've this code:
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse resp = client.execute(get);
HttpEntity entity = resp.getEntity();
InputStream input = entity.getContent();
...
//Read the bytes from input stream
This is the code I am using to download files over Http, I want to cancel the connection(may be user chooses to) What is the graceful way to close the connection. I found 2 ways, Both cancels the download.
- Closing inputsteram, input.close(); which causes IOException.
- Aborting HttpGet object, get.abort() causes SocketException.
I have try catch, so no erros, but without throwing exception, is there a way to cancel or abort the connection?
What is the right way to go about it ?