2012-11-07 21 views
5

Tôi muốn tải pdf với WebClient nhưng tôi cần gửi cookie với yêu cầuthêm cookie WebClient

Làm thế nào có thể thêm cookie WebClient sau đó tải pdf

WebClient webClient = new WebClient(); 

webClient.DownloadFile("http://........", "C://2.pdf"); 
+0

Hoặc sử dụng HttpWebRequest hoặc lớp WebClient và ghi đè 'GetWebRequest'' GetWebResponse' –

Trả lời

12

Bạn có thể thêm cookie vào webClient.

webClient.Headers.Add(HttpRequestHeader.Cookie, "cookies"); 
webClient.DownloadFile("http://........", "C://2.pdf"); 
1

WebClient không hỗ trợ cookie. Bạn cần tự thêm hỗ trợ cho các cookie ghi đè GetWebRequest hoặc chỉ cần sử dụng lớp HttpWebRequest.

Sample code here.

+4

Dunno nếu điều này là sự thật trong quá khứ, nhưng WebClient không hỗ trợ cookie ngày hôm nay. xem, ví dụ: -http: //stackoverflow.com/questions/12537064/httprequestheader-cookie-format – FuzzyAmi

Các vấn đề liên quan