如何强制终止 Http HEAD 命令(对于 HttpClient 和curl)?
如果运行此命令:
$ 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
您将立即注意到curl 命令挂起。 (我在 cygwin/VISTA 中运行它)
如果你在 twitter 或 facebook 上运行它,curl 会立即终止。 我怀疑这是因为 twitter & facebook 返回连接:关闭
。
在我的 Android 1.5 cupcake 应用程序中,我使用 HttpClient 框架运行相同的命令。我注意到连接挂起,但在超时后终止(感谢上帝 Http 4.0!!)。
是否有一个选项可以在 HttpClient 中设置,以在收到相关 HEAD 后终止 http 标头?
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 framework. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过将“Connection: close”标头添加到您的请求中?这应该告诉服务器您不需要持久连接。
Have you tried adding the "Connection: close" header to your request? That should tell the server that you don't want a persistent connection.