c# - 如何使用带有摘要式身份验证和查询字符串的 WebClient.DownloadFile

标签 c# .net apache webclient digest-authentication

如何将 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 webCl = new WebClient();
webCl.Credentials = new NetworkCredential("username", "Password");
webCl.DownloadFile(file download URL, fil save path with FileName);

关于c# - 如何使用带有摘要式身份验证和查询字符串的 WebClient.DownloadFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24399527/

相关文章:

c# - 将参数传递给 C# 中的工厂模式体系结构

c# - 从 Windows 窗体插入连接 SQL Server

c# - 文件存在 c# visual studio 2017

c# - 如何从 C# 代码调用 Google Geocoding 服务

c# - 是否可以获取作为 `params object[]` 传递的变量名称?

.net - 我们如何在查询中显示当前冲刺中完成的小时数

apache - .htaccess 的合适工作环境

apache - 删除所有子文件夹条件重写.htaccess Apache 1.3.42

.net - xmlwriter writedoctype格式化

java - 无法错误 : unable to get cib