http urlconnection getcontentlength总返回值为-1
来源:互联网 发布:细菌 线粒体 知乎 编辑:程序博客网 时间:2024/05/16 08:15
最近在做一个自动更新的功能,点击更新下载之后,进度条不走动。之前一直用的模拟器运行,没有发现任何问题,后来真机测试时就出现了进度条不走动的问题。经断点调试发现,当获取下载文件大小getContentLength()的时候,返回结果是-1。于是上网搜了一下HttpURLConnection及getContentLength(),发现2.2版本以上HttpURLConnection跟服务交互采用了”gzip”压缩:参考api:By default, this implementation of HttpURLConnection requests that servers use gzip compression. Since getContentLength() returns the number of bytes transmitted, you cannot use that method to predict how many bytes can be read from getInputStream(). Instead, read that stream until it is exhausted: whenread() returns -1.
解决办法:在http request的head中设置如下参数即可:conn.setRequestProperty(“Accept-Encoding”, “identity”);
0 0
- http urlconnection getcontentlength总返回值为-1
- 关于httpurlconnection getcontentlength返回值为-1的问题
- HTTP下载文件时getContentLength()返回-1
- HttpURLConnection getContentLength返回-1
- android getContentLength()函数返回为-1的问题
- getContentLength()为-1 解决方法
- getContentLength()为-1 解决方法
- getContentLength()为-1 解决方法
- HttpURLConnection.getContentLength()为-1 解决方法
- 使用HttpURLConnection的getContentLength()方法返回-1??
- connection.getContentLength()为负值
- 解决 HttpURLConnection类中getContentLength()方法返回-1问题
- 你看到的entity.getcontentlength返回-1了
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- C语言几种经典排序代码
- 利用referer防盗链
- 稀疏矩阵存储格式总结+存储效率对比:COO,CSR,DIA,ELL,HYB
- HttpClient使用详解
- LeetCode Construct Binary Tree from Preorder and Inorder Traversal
- http urlconnection getcontentlength总返回值为-1
- Android 开源项目android-open-project解析之(四) ColorPickView,GraphView,UI Style,Other
- 桥接模式
- Java-静态代码块
- Dijkstra 算法
- PHP 继承与实现比较 final和const修饰符说明
- 计算机图形学-多边形填充法
- getRequestDispatcher 和sendRedirect区别
- 我的第一篇csdn笔记