下载网络文件HttpURLConnection.getContentLength()大小为 0

来源:互联网 发布:linux vim 显示行数 编辑:程序博客网 时间:2024/06/05 10:23
默认情况下,HttpURLConnection使用gzip方式获取,要取得长度则要求http请求不要gzip压缩;

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Accept-Encoding", "identity"); // 添加这行代码
conn.connect();

int length = conn.getContentLength();


参考:http://blog.csdn.net/maxracer/article/details/7096000

0 0
原创粉丝点击