使用分块http传输时获取文件总长度 [英] Getting total file length when using chunked http transfers
问题描述
如果服务器提供 Content-Length
标题字段,那很简单。如果没有的话,那么你的运气不好。
合理的服务器实现提供了 Content-Length
内容是静态的并且具有已知的大小。如果内容是动态生成的,那么不可能知道先验的长度,至少不需要进行两次数据传递。
I've written a program in Java to use chunking to download large files over http. Everything is working fine but I'd like to add a progress bar which I can't do unless I get the total length of the file. Is there any way to do this?
If the server provides a Content-Length
header field, then that's easy. If it doesn't, then you're out of luck.
Reasonable server implementations provide Content-Length
when the content is static and has a known size. If the content is dynamically generated, then it's impossible to know the length a priori, at least without making two passes through the data.
这篇关于使用分块http传输时获取文件总长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!