我希望能够在不下载远程文件的情况下知道其大小。我知道有一些使用“Content-length” header 值的解决方案,但对于某些链接,此 header 丢失。在这种情况下,解决方案是下载整个文件,但如果文件大于 1Gb,会发生什么情况。
下载管理器使用什么方式来查找远程文件的大小?
如果您有任何语言的解决方案,我会采纳。谢谢。
最佳答案
Content-length
是一个可选 header ,用于指定 HTTP 协议(protocol)中资源的长度。
以下是一些详细信息:HTTP/1.1: Header Field Definitions - 14.13 Content-Length
基本上,这是值得注意的部分:
Applications SHOULD use this field to indicate the transfer-length of the message-body, unless this is prohibited by the rules in section 4.4.
以及4.4 Message Length部分应该对你也有帮助。
I know there is some solutions using the "Content-length" header but for few links it doesn't exist.
如果服务器不发送任何类型的 Content-Length,则无法确定其大小(4.4 节中描述的特殊情况除外)。因此,下载管理器将事先不知道长度,并且将下载它获得的所有内容,直到服务器停止向其提供数据。
关于http - 如何知道内容长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10328675/