Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将WebClient.DownloadFile与摘要身份验证和查询字符串一起使用_C#_.net_Apache_Webclient_Digest Authentication - Fatal编程技术网

C# 如何将WebClient.DownloadFile与摘要身份验证和查询字符串一起使用

C# 如何将WebClient.DownloadFile与摘要身份验证和查询字符串一起使用,c#,.net,apache,webclient,digest-authentication,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> 也许你应该在请求后得到401

如何将
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>

也许你应该在请求后得到401回复。401响应包含计算质询响应所需的WWW Authenticate标头。查看摘要身份验证协议的工作原理@MikeHixson我得到了401罚款,这是之后失败的请求。请尝试以下链接中的解决方法,仅用于调试目的硬编码凭证缓存“http://example.com”上的url,并查看是否有任何更改。
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);