查看文章 |
[转]使用WebClient的时候如何处理Cookie
2008-09-21 18:53
WebClient: Handling CookiesWebClient class is very useful when you need to download or upload date from or to the Web. However, when you need to make a sequence of calls you find that WebClient does not preserve cookies set by the server between requests. Fortunately, WebClient gives you an opportunity to handle cookies by yourself.在从Web服务器上下载文件或者往上传数据的时候,WebClient类是非常有用的。不过当你需要跟服务器做一系列的交互时会发现WebClient类根本不处理Cookie。 幸好,WebClient类提供了一个让你自己处理Cookie的机会。 The very simple solution is to override GetWebRequest method of the WebClient class and set CookieContainer property. Here is my implementation: public class CookieAwareWebClient : WebClient |
最近读者: