【发布时间】:2023-03-06 14:31:01
【问题描述】:
我正在使用来自 Apache Commons 的 HttpClient 对文件进行简单请求。这是我当前的代码:
httpclient = new DefaultHttpClient();
httpget = new HttpGet(location);
context = new BasicHttpContext();
response = httpclient.execute(httpget, context);
entity = response.getEntity();
我需要怎么做才能在下载过程中取消这个请求?
【问题讨论】:
-
请求这么简单,你需要Apache commons干什么?
-
+1 @Thomas 的评论。为什么不直接使用
java.net?然后,您可以随时轻松关闭流。 -
嗯...目前很简单,但可能会变得更加复杂。稍后我将添加几个自定义 HTTP 标头。
标签: java apache-httpclient-4.x