简体   繁体   English

从 Javascript 发送分块 HTTP 请求

[英]Sending Chunked HTTP request from Javascript

This question shows how to read a chunked response in Javascript, but I would like to send a chunked HTTP POST from Javascript. 这个问题显示了如何在 Javascript 中读取分块响应,但我想从 Javascript发送分块 HTTP POST。 Thedocumentation for XMLHttpRequest doesn't mention anything. XMLHttpRequest 的文档没有提及任何内容。 Does the answer to this question mean that it's not possible due to browser restrictions on setting the header? 这个问题的答案是否意味着由于浏览器对设置标题的限制而无法实现?

I don't think you can with XMLHttpRequest - it's old and somewhat limited, it's really just a backwards compatibility hack for a long-gone IE ActiveX component.我不认为你可以使用XMLHttpRequest - 它很旧而且有些限制,它实际上只是一个长期消失的 IE ActiveX 组件的向后兼容性黑客。

However, at the bleeding edge (not in Firefox yet) you can with fetch and TransformStream .但是,在最前沿(Firefox 中还没有),您可以使用fetchTransformStream This lets you send a stream from JS .这使您可以从 JS发送

Refer to this MDN page about Transfer-Encoding .请参阅有关Transfer-Encoding 的此 MDN 页面。 You can set the type to chunked.您可以将类型设置为分块。

You have to specify how long each chunk will be, but it allows you to send data in chunks.您必须指定每个块的长度,但它允许您以块的形式发送数据。

I think XMLHttpRequest is very old, I think the alternative is to use Axios which is a newer JavaScript package which helps to handle network requests.我认为 XMLHttpRequest 很旧,我认为替代方案是使用Axios ,它是一个较新的 JavaScript 包,有助于处理网络请求。 It is much more easier than fetch and ajax in JavaScript.它比 JavaScript 中的fetchajax容易得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM