从 apache 服务器下载时此代码可以正常工作,没有问题。但是当使用iis 7.5进行测试时,当前安装在win7上。它似乎不适用于 getInputStream();尽管在调试并将其粘贴到浏览器中时会显示文件的完整地址,但会开始下载 apk
阅读本网站和互联网已添加 MIME TYPE .apk application/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();
}
最佳答案
只需删除此代码即可:
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
第一个不是必需的,第二个,c.setDoOutput(true);
正在将请求方法更改为POST ...
这就是为什么你会收到 405 method not allowed ...
关于android - 从 IIS 7.5 下载 APK 下载失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12838259/