将cookie添加到WebClient
我想用WebClient
下载pdf,但我需要发送cookie请求
如何将cookie添加到WebClient
然后下载pdf
WebClient webClient = new WebClient(); webClient.DownloadFile("http://........", "C://2.pdf");
您可以向webClient添加cookie。
webClient.Headers.Add(HttpRequestHeader.Cookie, "cookies"); webClient.DownloadFile("http://........", "C://2.pdf");
WebClient
不支持cookie。 您需要自己重新添加对GetWebRequest
支持,或者只使用HttpWebRequest
类。
示例代码在这里。