getContentLength()为-1 解决方法
2014-05-09 17:39
585 查看
最近在做一个下载平台,用到多线程下载和断点续传功能,当我获取文件大小getContentLength()的时候,返回结果是-1。文件下载是没问题的,但是大小却不正常,用模拟器获取getContentLength()是正常的,但是真机却返回-1了,模拟器是低版本运行,于是我就猜想是版本问题,果然2.2版本以上HttpURLConnection跟服务交互采用了"gzip"压缩:参考api:By default, this implementation of
that servers use gzip compression. Since
of bytes transmitted, you cannot use that method to predict how many bytes can be read from
Instead, read that stream until it is exhausted: when
取消办法这http request的head中设置如下参数即可:connection.setRequestProperty("Accept-Encoding", "identity");
HttpURLConnectionrequests
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: when
read()returns -1.
取消办法这http request的head中设置如下参数即可:connection.setRequestProperty("Accept-Encoding", "identity");
相关文章推荐
- Android getContentLength()为-1 解决方法
- getContentLength()为-1 解决方法
- 解决 HttpURLConnection类中getContentLength()方法返回-1问题
- getContentLength()为-1 解决方法
- Connect getContentLength = -1问题的解决方法
- HttpURLConnection.getContentLength()为-1 解决方法
- 遇到问题---java获取网络文件大小失败getContentLength()为-1 完整解决方法
- 遇到问题---java获取网络文件大小失败getContentLength()为-1 完整解决方法
- getContentLength()= -1 解决方法
- Bytes to be written to the stream exceed the Content-Length bytes size specified 解决方法
- 对于未扩展file_get_content的服务器的自写类的解决方法
- jar包冲突解决(getTextContent()方法无法找到)
- java.lang.NullPointerException: Attempt to get length of null array的解决方法
- 关于inputStream.available()与HttpURLConnection.getContentLength()方法获取下载文件的大小
- 使用HttpURLConnection的getContentLength()方法返回-1??
- 关于The target "GetCopyToOutputDirectoryContentProjectItems" does not exist in the project.的解决方法
- 关于inputStream.available()与HttpURLConnection.getContentLength()方法获取下载文件的大小
- javamail的getContent()抛出UnsupportedEncodingException的解决方法
- jar包冲突解决(getTextContent()方法无法找到)
- eclipse:xml-apis jar包冲突导致的getTextContent()方法无法找到解决