如何使用WebClient.带有摘要身份验证和查询字符串的下载文件

本文关键字:查询 字符串 文件 下载 身份验证 WebClient 何使用 | 更新日期: 2023-09-27 18:10:20

我如何使用WebClient.DownloadFile与摘要身份验证和查询字符串?

当我尝试使用它时,我得到一个401响应。

Apache的错误日志:

[Tue Jun 24 17:31:49 2014] [error] [client x.x.x.x] Digest: uri mismatch - </file-1.php> does not match request-uri </file-1.php?since=1403587422>

下面是我下载文件的方法:

Uri uri = new Uri("http://example.com/file-1.php?since=1403587422");
WebClient webClient = new WebClient();
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(
  new Uri(uri.GetLeftPart(UriPartial.Authority)),
  "Digest",
  new NetworkCredential("username", "password")
);
webClient.Credentials = credentialCache;
webClient.DownloadFile(uri, file.OutputFile);

如何使用WebClient.带有摘要身份验证和查询字符串的下载文件

WebClient webCl = new WebClient();
webCl.Credentials = new NetworkCredential("username", "Password");
webCl.DownloadFile(file download URL, fil save path with FileName);