尝试下载apk文件时找不到文件异常

时间:2012-04-16 23:18:52

标签: android iis-7

我有一个在iis 7中托管的android apk文件,我想从Android应用程序中下载和安装。我非常依赖this question中的代码,但我在InputStream is = con.getInputStream();

获取了一个fileNotFound异常

我可以在我的桌面和手机(三星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.

1 个答案:

答案 0 :(得分:0)

不应该是GET,而不是POST?