开发者

how to reuse httpclient connection to get multiple small files

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 resp开发者_开发百科onse 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?


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/1.1 defines the "close" connection option for the sender to signal that the connection will be closed after completion of the response. For example,

   Connection: close

in either the request or the response header fields indicates that the connection SHOULD NOT be considered `persistent' (section 8.1) after the current request/response is complete.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜