是否可以设置内容长度 header 并使用分块传输编码?这样做是否解决了使用分块时客户端不知道响应长度的问题?
我正在考虑的场景是当您有一个大文件要传输并且确定其大小没有问题,但它太大而无法完全缓冲时。 (如果您不使用分块,那么必须先缓冲整个响应?对吗??)
谢谢。
最佳答案
- 否:
"Messages MUST NOT include both a Content-Length header field and a non-identity transfer-coding. If the message does include a non-identity transfer-coding, the Content-Length MUST be ignored." (RFC 2616, Section 4.4)
- 不,您可以使用 Content-Length 和流;该协议(protocol)不会限制您的实现方式。
关于http - 分块编码和内容长度 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3304126/