二郎。异步http请求。如何知道连接何时断开?
使用 httpc
HTTP 向某个服务器发出异步请求客户端
httpc:request(get, {Url, []}, [], [{sync, false}, {stream,
self}])
,其中 Url
是服务器的 URL。数据接收者 gen_server
中的 handle_info/2
调用了 httpc:request/4
,但当连接断开并且没有 时我应该收到消息Stream_end
消息。使用超时对我来说不可行,因为服务器响应可能需要很长时间。
是否可以在 handle_info/2
中获取有关连接断开的消息?如果没有,请建议如何知道连接何时断开?
Making an asynchronous request to some server using the httpc
HTTP client
httpc:request(get, {Url, []}, [], [{sync, false}, {stream,
self}])
where Url
is the URL of the server. Data is received byhandle_info/2
in gen_server
that called httpc:request/4
but I should get message when the connection is broken and there is no stream_end
message. Using timeout is not feasible for me, because server response can take a long time.
Is it possible to get message about a broken connection in handle_info/2
? If not, please suggest way to know when the connection is broken?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要更繁重地提升 HTTP 请求,请使用 ibrowse:
https://github.com/cmullaparthi/ibrowse
它有更多的旋钮可以根据要求扭转和转动,并且在很多方面都更加完整。如果 http/httpc 不能解决您的问题,那么值得研究一下 ibrowse 是否可以解决您的问题。
For more heavy-duty lifting of HTTP requests, use ibrowse:
https://github.com/cmullaparthi/ibrowse
It has many more knobs to twist and turn for requests and is more complete w.r.t. many things. If http/httpc doesn't solve your problem, it is worth investigating if going to ibrowse will.