如何让 Apache Http 客户端在超时后恢复等待响应?
我使用 Apache Http 客户端的executeMethod,它会阻塞直到收到服务器响应。我可以设置超时,但一旦超时到期,客户端似乎无法恢复等待响应。
我可以让 Apache Http 客户端在超时后恢复等待响应吗?
I use executeMethod
of Apache Http client, which blocks until it receives the server response. I can set the timeout but it looks like that the client cannot resume waiting for response once the timeout is expired.
Can I make Apache Http client resume waiting for response after the timeout ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
超时意味着就您的应用程序而言,您已完成等待响应的操作。如果您打算继续等待并且只想偶尔做一些事情,我建议您使用单独的线程进行 Http 连接。然后您可以在继续等待的同时做您需要做的事情。如果您决定停止等待,您应该能够终止连接。
Timeout means that for purposes of your application, you are done waiting for response. If you intend to continue waiting and just want to do something every once in a while, I'd suggest you use separate thread for Http connection. Then you can do what you need while continue waiting. And you should be able to kill the connection if you decide to stop waiting.
我认为您设置的超时实际上是套接字超时,因此当它到期时套接字将关闭,您需要重复executeMethod 调用。
I think that the timeout you set is actually the socket timeout, so when it expires the socket closes and you need to repeat the executeMethod call.
创建一个单独的线程并阻止执行方法。当超时时,再次重复该过程。
Create a separate thread and block on execute method. When it times out repeat the process once again.