取消HttpClient请求 [英] Cancel an HttpClient request

查看:298
本文介绍了取消HttpClient请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache Commons的HttpClient对文件进行简单的请求。这是我目前的代码:

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?

推荐答案

您可以使用 httpget.abort()方法在中途中止请求。

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

参见示例这里

这篇关于取消HttpClient请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆