Elixir:HTTPResponseStream使用流式API
我想写一个可以使用流式API的客户端。本质上,有一个getter返回HTTPResponseStream而不是HTTPResponse。我在HTTPotion中找不到一个,所以我想我应该试试。但是我不知道该怎么做,我真的很感谢你的帮助 您可以使用HTTPotion执行异步请求,如下所示:Elixir:HTTPResponseStream使用流式API,http,stream,elixir,twitter-streaming-api,Http,Stream,Elixir,Twitter Streaming Api,我想写一个可以使用流式API的客户端。本质上,有一个getter返回HTTPResponseStream而不是HTTPResponse。我在HTTPotion中找不到一个,所以我想我应该试试。但是我不知道该怎么做,我真的很感谢你的帮助 您可以使用HTTPotion执行异步请求,如下所示: %HTTPotion.AsyncResponse{ id: id } = HTTPotion.get "http://example.com", [], [stream_to: self] 这将向当前流程发送
%HTTPotion.AsyncResponse{ id: id } = HTTPotion.get "http://example.com", [], [stream_to: self]
这将向当前流程发送三种不同类型的消息(通过self
定义):
该id可用于处理来自多个正在进行的请求的响应
# First, the response headers
%HTTPotion.AsyncHeaders{ id: ^id, status_code: 200, headers: _headers }
# Then, one or more chunks
%HTTPotion.AsyncChunk{ id: ^id, chunk: _chunk }
# And finally, an end message
%HTTPotion.AsyncEnd{ id: ^id }