Android 如何下载受NTLM身份验证保护的文件

Android 如何下载受NTLM身份验证保护的文件,android,android-download-manager,ntlm-authentication,Android,Android Download Manager,Ntlm Authentication,我尝试过用Android的DownloadManager API下载,但没有成功 这是我的示例代码,它返回我下载失败 webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long conte

我尝试过用Android的DownloadManager API下载,但没有成功

这是我的示例代码,它返回我下载失败

webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
            DownloadManager.Request request = new DownloadManager.Request(
                    Uri.parse(url));
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
            DownloadManager dm = (DownloadManager) MainActivity.this.getSystemService(MainActivity.this.DOWNLOAD_SERVICE);
            dm.enqueue(request);
        }
    });

在创建新网站时转到IIS管理器和

在身份验证->选择windows身份验证->提供程序->删除协商并仅保留NTLM

并参考下面的链接下载NTLM保护的文件。

至于我,您的代码运行良好。这是我的代码,没有变化。既然我不想帮助你,你应该发布你的下载服务器IP如果可以的话。所以我可以测试你的服务器

我的服务器是ApacheWeb服务器,因为它是我们的生产服务器之一,请原谅我无法表达我的服务器。问题可能是您的web服务器配置或凭据或安全证书

        WebView webview = new WebView(FileDownloadActivity.this);
        webview.loadUrl("http://167.172.70.x/xxxxxxxxx-version-1.9.apk");

        webview.setDownloadListener((url, userAgent, contentDisposition, mimeType, contentLength) ->
        {
            String fileName = URLUtil.guessFileName(url, contentDisposition, mimeType);
            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
            DownloadManager downloadmanager = (DownloadManager) getApplicationContext().getSystemService(FileDownloadActivity.this.DOWNLOAD_SERVICE);
            downloadmanager.enqueue(request);
        });

您可以添加适当的请求头来完成身份验证。上面的链接解释了NTLM(新技术LAN Manager)协议。您的服务器的身份验证类型是NTLM吗?