从IIS 7.5下载APK到下载失败

时间:2012-10-11 11:16:31

标签: android apk downloading

从apache服务器下载时此代码无效。但是当在win7上安装使用iis 7.5 currenlty进行测试时。它似乎不适用于getInputStream();虽然在debuging和粘贴时显示文件的完整地址,但浏览器开始下载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();
                        }

1 个答案:

答案 0 :(得分:2)

刚刚摆脱这段代码:

      c.setRequestMethod("GET");
      c.setDoOutput(true);
      c.connect();

首先没有必要,第二,c.setDoOutput(true);正在将请求方法更改为POST ... 这就是为什么你不允许405方法......