2014-06-25 15 views
11

Làm cách nào để sử dụng WebClient.DownloadFile với xác thực thông báo và chuỗi truy vấn?Cách sử dụng WebClient.DownloadFile với xác thực thông báo và chuỗi truy vấn

Khi tôi cố gắng sử dụng, tôi nhận được phản hồi 401.

Đây là lỗi Apache 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> 

Sau đây là cách tôi cố gắng để tải về các tập tin:

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

lẽ http://stackoverflow.com/questions/3172510/ how-can-i-do-digest-authentication-with-httpwebrequest – Brian

+0

Bạn được yêu cầu nhận phản hồi 401 sau yêu cầu. Phản hồi 401 chứa tiêu đề WWW-Authenticate mà bạn cần để tính toán phản hồi thách thức. Xem cách giao thức xác thực thông báo hoạt động. http://technet.microsoft.com/en-us/library/cc780170(v=ws.10).aspx –

+0

@MikeHixson Tôi nhận được tiền phạt 401, yêu cầu của nó sau đó không thành công. – Petah

Trả lời

1
WebClient webCl = new WebClient(); 
webCl.Credentials = new NetworkCredential("username", "Password"); 
webCl.DownloadFile(file download URL, fil save path with FileName); 
Các vấn đề liên quan