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



我尝试使用Android的DownloadManager apis下载,但失败了。

这是我的示例代码,它返回我下载不成功。

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);
}
});

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

我的服务器是 apache Web 服务器,由于它是我们的生产服务器之一,请原谅我,因为我无法表达我的服务器。问题可能是您的 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);
});

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

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

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

最新更新