开发者

Cancel an HttpClient request

开发者 https://www.devze.com 2023-02-19 16:01 出处:网络
I am making a simple request for a file using HttpClient from the Apache Commons. Here is my current code:

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 BasicHttpCo开发者_高级运维ntext();
    response = httpclient.execute(httpget, context);
    entity = response.getEntity();

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


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

See example here

0

精彩评论

暂无评论...
验证码 换一张
取 消