使用分块http传输时获取文件总长度 [英] Getting total file length when using chunked http transfers

查看:212
本文介绍了使用分块http传输时获取文件总长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Java写了一个程序来使用chunking通过http下载大文件。一切工作正常,但我想添加一个进度条,我不能做,除非我得到的文件的总长度。有没有办法做到这一点?

解决方案

如果服务器提供 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆