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