Bra*_*rad 15 stream fetch fetch-api whatwg-streams-api
我试图用取一个ReadableStream.在这个例子中,ReadableStream应该无限期地重复"Some data ...".
fetch('/', {
method: 'POST',
body: new ReadableStream({
pull: function(controller) {
console.log('pull called!');
controller.enqueue('Some data...');
}
})
});
Run Code Online (Sandbox Code Playgroud)
这不起作用.而pull
被执行一次,没有数据被请求体中的发送.
POST / HTTP/1.1
Host: example.com
Connection: keep-alive
Content-Length: 0
Origin: https://example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36
Accept: */*
Referer: https://example.com/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
Run Code Online (Sandbox Code Playgroud)
如何使用fetch可用的ReadableStream(或任何我可以编写动态数据的流)?
或者,如果这还不可能,请您说明一下吗?谢谢.
注意:这是一个更具体的衍生问题: 通过HTTP将数据从浏览器传输到服务器的方法
我们正在努力完成这项工作,请参阅https://github.com/whatwg/fetch/pull/425获取PR的Fetch标准.一旦完成,你可以期待这种方式进入浏览器(慢慢地).