How to use WebClient.DownloadFile with digest authentication and a query string
Asked Answered
M

1

11

How do I use WebClient.DownloadFile with digest authentication and a query string?

When I try to use it I get a 401 response.

This is the Apache error log:

[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>

Here is how I try to download the file:

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);
Monotint answered 25/6, 2014 at 3:4 Comment(7)
Perhaps #3173010Soph
You are supposed to get a 401 response after the request. The 401 response contains the WWW-Authenticate header that you need to calculate the challenge response. Check out how the digest authentication protocol works. technet.microsoft.com/en-us/library/cc780170(v=ws.10).aspxHypnotist
@MikeHixson I get the 401 fine, its the request after that which fails.Monotint
Try the workaround in the below link <connect.microsoft.com/VisualStudio/feedback/details/571052/…>Buckra
just for debug purpose hard-code the url on the credentialCache "http : //example.com" and see if anything changes.Fled
@Monotint Maybe this will help? httpd.apache.org/docs/2.0/mod/mod_auth_digest.html Try adding this to your httpd.conf BrowserMatch "MSIE" AuthDigestEnableQueryStringHack=OnPardo
@Monotint This is where I found it originally: drupal.org/node/128962Pardo
U
2
WebClient webCl = new WebClient();
webCl.Credentials = new NetworkCredential("username", "Password");
webCl.DownloadFile(file download URL, fil save path with FileName);
Ursula answered 5/6, 2015 at 3:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.