取消 HttpClient 请求

2022-09-02 20:52:56

我正在从Apache Commons使用HttpClient对文件提出一个简单的请求。这是我当前的代码:

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

在下载过程中,我需要执行哪些操作才能取消此请求?


答案 1

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

在此处查看示例


答案 2

推荐