Ben Kulbertis
Ben Kulbertis

Reputation: 1713

Cancel an HttpClient request

I am making a simple request for a file using HttpClient from the Apache Commons. Here is my current code:

    httpclient = new DefaultHttpClient();
    httpget = new HttpGet(location);
    context = new BasicHttpContext();
    response = httpclient.execute(httpget, context);
    entity = response.getEntity();

What would I need to do to cancel this request in the middle of the download?

Upvotes: 18

Views: 19612

Answers (1)

Suresh Kumar
Suresh Kumar

Reputation: 11787

You can use httpget.abort() method to abort the request mid way.

See example here

Upvotes: 30

Related Questions