取消HttpClient请求

时间:2011-03-23 02:37:53

标签: java apache-httpclient-4.x

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

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

在下载过程中取消此请求需要做什么?

2 个答案:

答案 0 :(得分:30)

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

参见示例here

答案 1 :(得分:4)

文档中的link似乎包含您要查找的内容。