Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 590
Petah Avatar asked Jun 25 '14 03:06

Petah


1 Answers

WebClient webCl = new WebClient();
webCl.Credentials = new NetworkCredential("username", "Password");
webCl.DownloadFile(file download URL, fil save path with FileName);
like image 149
Kanishka Avatar answered Oct 17 '22 07:10

Kanishka