新版本下载时,downloadtask.java 接收到的 count 值是-1
kkpyqt opened this issue · 3 comments
我用的json 与demo 是一致的
单独请求apk 下载url 是正常可下载的,不清楚为什么得不到下载文件的大小
{"versionCode":2,"versionName":"1.4.12","content":"1.优化功能#2.增加功能","minSupport":1,"url":"http://47.97.213.223:8080/services/download/testDownload/app.apk"}
这个请求返回为-1 ,在6.0 版本里,大师有解决办法没?
string mDownLoadUrl ="http://47.97.213.223:8080/services/download/testDownload/yn.apk";
URL url = new URL(mDownLoadUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(5000); //
connection.setReadTimeout(5000);
connection.setRequestProperty("Connection", "Keep-Alive");
// connection.setRequestProperty("Keep-Alive", "header");
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept-Encoding", "identity");
connection.connect();
int fileLength = connection.getContentLength();
Log.i(TAG,"文件大小为:"+fileLength+"btye");
已经解决,在服务器中设置response.setContentLength(
);
String fullPath = "E:/" + id +".rmvb";
File downloadFile = new File(fullPath);
response.setContentLength((int) downloadFile.length());
客户端增加
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept-Encoding", "identity");
connection.connect();