Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir:HTTPResponseStream使用流式API_Http_Stream_Elixir_Twitter Streaming Api - Fatal编程技术网

Elixir:HTTPResponseStream使用流式API

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] 这将向当前流程发送

我想写一个可以使用流式API的客户端。本质上,有一个getter返回HTTPResponseStream而不是HTTPResponse。我在HTTPotion中找不到一个,所以我想我应该试试。但是我不知道该怎么做,我真的很感谢你的帮助

您可以使用HTTPotion执行异步请求,如下所示:

%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 }