【问题标题】:How to Download NTLM Authentication Protected Files如何下载受 NTLM 身份验证保护的文件
【发布时间】:2019-12-31 11:14:04
【问题描述】:

我曾尝试使用 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);
        }
    });

【问题讨论】:

标签: android android-download-manager ntlm-authentication


【解决方案1】:

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

我的服务器是 apache 网络服务器,由于它是我们的生产服务器之一,请原谅我无法表达我的服务器。问题可能出在您的 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 管理器)协议。
  • 你服务器的认证类型是 NTLM 吗?
【解决方案2】:

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

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

并参考以下链接下载受 NTLM 保护的文件。 https://github.com/square/okhttp/issues/206

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    相关资源
    最近更新 更多