将cookie添加到WebClient

时间:2012-11-07 17:33:33

标签: c#

我想用WebClient下载pdf,但我需要发送带请求的cookie

如何将Cookie添加到WebClient然后下载pdf

 WebClient webClient = new WebClient();

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

1 个答案:

答案 0 :(得分:14)

您可以向您的webClient添加Cookie。

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