0

我有一个托管在 iis 7 中的 android apk 文件,我想从一个 android 应用程序中下载并安装它。我非常依赖这个问题中的代码,但我在收到 fileNotFound 异常InputStream is = con.getInputStream();

我可以在我的桌面和手机(三星 Galaxy Nexus)上的浏览器中下载 apk 文件,并且我已将 apk mime 类型添加到 iis。

这是我的代码。

protected Void doInBackground(Void... params) {
        try {
            URL url = new URL("http://android.atomweb.net.au/CasLite.apk");
            HttpURLConnection con = (HttpURLConnection) url.openConnection();

            con.setRequestMethod("POST");
            con.setDoOutput(true);
            con.connect();

            String PATH = Environment.getExternalStorageDirectory() + "/download/";
            File file = new File(PATH);
            file.mkdirs();
            File outputFile = new File(file, "app.apk");
            FileOutputStream fos = new FileOutputStream(outputFile);

            InputStream is = con.getInputStream();

            byte[] buffer = new byte[1024];
            int len1 = 0;
            while ((len1 = is.read(buffer)) != -1) {
                fos.write(buffer, 0, len1);
            }

            fos.close();
            is.close();

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(
                    Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")),
                    "application/vnd.android.package-archive");

            startActivity(intent);

        } catch (IOException e) {
            Log.d("Error", e.getLocalizedMessage());
        }
        return null;

    }

当我在建立连接之后但在 getInputStream 之前发布断点并查看连接响应代码时,它是 405。

4

1 回答 1

0

那不应该是 GET,而不是 POST 吗?

于 2012-04-16T23:23:07.310 回答