开发者

How to force a Http HEAD command to terminate (for HttpClient and curl)?

开发者 https://www.devze.com 2022-12-11 02:43 出处:网络
If you run this command: $ curl -XHEAD -i -H \"User-Agent: myuseragent\" http://www.google.com HTTP/1.1 302 Found

If you run this command:

$ curl -XHEAD -i -H "User-Agent: myuseragent" http://www.google.com
HTTP/1.1 302 Found 
... snip ...
Server: gws
Content-Length: 222
X-XSS-Protection: 0

you will notice immediately that the curl command hangs. (I am running this in cygwin/VISTA)

If you run it against twitter or facebook, curl terminates immediately. I suspect it's because twitter & facebook returns Connection: close.

In my Android 1.5 cupcake app, I am running the same command using the HttpClient f开发者_JAVA技巧ramework. And I notice that the connection hangs but terminates after the timeout (Thank god for Http 4.0 !! ).

Is there an option to set in HttpClient to terminate once I've received the relevant HEAD http headers?


Have you tried adding the "Connection: close" header to your request? That should tell the server that you don't want a persistent connection.

0

精彩评论

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