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

查看:51
本文介绍了取消 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天全站免登陆