WebBrowser的Cookie与HttpRequest交互
一直都在找关于如何将WebBrowser的Cookie 转化为CookieContainer
今天发现一个简单快捷的方式 与大家分享
HttpWebRequest httpWebRequest; httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); httpWebRequest.CookieContainer = cc; httpWebRequest.ContentType = contentType; httpWebRequest.Referer = url; httpWebRequest.Accept = accept; httpWebRequest.UserAgent = userAgent; httpWebRequest.Method = "GET"; foreach (var item in CookieString.Split(';')) { httpWebRequest.CookieContainer.SetCookies(new Uri(url), item); }
用这种形式即可把字符串的Cookie 转化为CookieContainer
传给WebBrowser 直接把用httpWebRequest.CookieContainer.GetCookies(new Uri(url));
这样就好了