解决 HttpURLConnection类中getContentLength()方法返回-1问题
来源:互联网 发布:python可以开发网站吗 编辑:程序博客网 时间:2024/06/05 02:26
下午写练习是发现 conn.getContentLength()总是返回-1,经查阅很多资料才知道需要在conn.setRequestMethod("GET");后面增加一句conn.setRequestProperty("Accept-Encoding", "identity"),才能获取到getContentLength()的值URL url2 = new URL(url);HttpURLConnection conn = (HttpURLConnection) url2.openConnection();conn.setConnectTimeout(5000);conn.setRequestMethod("GET");conn.setRequestProperty("Accept-Encoding", "identity"); if (conn.getResponseCode() == 200) { maxLength = conn.getContentLength(); mPbar.setMax(maxLength); InputStream is = conn.getInputStream(); String fileName = url.substring(url.lastIndexOf("/")); FileOutputStream os = new FileOutputStream(Constant.SD_CARD + "/" + fileName); int len = 0; byte[] buffer = new byte[1024]; while ((len = is.read(buffer)) != -1) { this.publishProgress(len); os.write(buffer, 0, len); } os.close(); is.close(); Bitmap bitmap = BitmapFactory.decodeFile(Constant.SD_CARD + "/" + fileName); return bitmap;}
0 0
- 解决 HttpURLConnection类中getContentLength()方法返回-1问题
- 使用HttpURLConnection的getContentLength()方法返回-1??
- HttpURLConnection getContentLength返回-1
- 关于httpurlconnection getcontentlength返回值为-1的问题
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- Android HttpURLConnection.getContentLength() 等于 -1
- Android HttpURLConnection.getContentLength() 等于 -1
- HttpURLConnection.getContentLength()为-1 解决方法
- android getContentLength()函数返回为-1的问题
- HTTP下载文件时getContentLength()返回-1
- 下载网络文件HttpURLConnection.getContentLength()大小为 -1
- 下载网络文件HttpURLConnection.getContentLength()大小为 -1
- 下载网络文件HttpURLConnection.getContentLength()大小为 -1
- readdir(系统调用)
- LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- CPU上涨100%的问题排查
- SQL Server 2008 清空删除日志文件 130G日志 10秒内变10M
- RunTime.getRunTime().addShutdownHook用法
- 解决 HttpURLConnection类中getContentLength()方法返回-1问题
- Linux读取目录函数readdir以及inode结构简介
- const 与重载
- Codeforces Round #305 (Div. 1) B. Mike and Feet
- Const 重载解析
- const 和 非const函数重载
- vs2010下C++调用lib或dll文件
- swift 集合类
- 如何零基础的学习java