如何重用httpclient连接获取多个小文件
我正在使用 httpclient 连续从服务器下载多个小文件。所以我想重用httpclient连接以避免花费大量时间来分配新连接。
我已经有一些客户端代码来尝试重用连接,并将现有连接的空闲超时设置为 3 分钟。
然而,服务器的响应总是包含“Connection: close[\r][\n]”,httpclient 库在遇到此类标头后立即释放连接。
我该如何让httpclient忽略来自服务器的响应,或者我发布的哪个标头可以让服务器不再返回这样的结束标头?
I'm using httpclient to download multiple small files from server continuously. So I want to reuse the httpclient connection to avoid costing a lot of time to allocate new connection.
And I already have some client code to try to reuse the connection, and set the idle timeout of existing connection to 3 minutes.
However the response from server always contains "Connection: close[\r][\n]", httpclient library releases the connection immediately after it meets such header.
How do I do to let httpclient to ignore the response from server, or which header I post could let server no longer return such closing header?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使您设法忽略
Connection: close
标头,我也不认为“违反”该指令是一个好主意。RFC 表示以下内容
Even if you manage to ignore the
Connection: close
header, I don't think it would be a good idea "violate" the directive.The RFC says the following
您需要向 HTTP 请求添加 keep-alive 标头。
http://download.oracle.com/ javase/1.5.0/docs/guide/net/http-keepalive.html
https://www.rfc-editor.org/rfc/rfc1122#page- 101
http://httpd.apache.org/docs/1.3/keepalive.html
You need to add a keep-alive header to your HTTP requests.
http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html
https://www.rfc-editor.org/rfc/rfc1122#page-101
http://httpd.apache.org/docs/1.3/keepalive.html