此代碼在從apache服務器下載時沒有任何問題。但在使用安裝在win7上的iis 7.5 currenlty進行測試時。它似乎並沒有在getInputStream();雖然文件的完整地址正在顯示,當調試和粘貼到瀏覽器開始下載apk文件時,請點擊這裏。從IIS 7.5下載APK到下載失敗
閱讀本網站和互聯網已添加MIME類型.apk應用程序/ vnd.android.package-archive
try {
URL url = new URL(prefs.getString("server_address", null) + "/updates/filename.apk");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "filename.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (IOException e) {
Toast.makeText(context, "error!", Toast.LENGTH_LONG).show();
}
你沒有檢查狀態:'int code = httpConnection.getResponseCode();'你能添加這段代碼並告訴我們你在代碼var中得到了什麼嗎? – Selvin
你是什麼意思「它似乎不工作在getInputStream();」?你是否檢查過網絡通訊,例如通過在服務器上使用Wireshark? – Robert
感謝您的快速回復代碼是405 – RuAware