开发者

How do I copy all cookies from a WebBrowser class and put them in a CookieCollection?

开发者 https://www.devze.com 2023-02-04 04:48 出处:网络
The title pretty much stands for itself. But I am using an HTTPWebRequest to download pages from the internet, but these p开发者_StackOverflowages require a login, so you log in with the WebBrowser an

The title pretty much stands for itself. But I am using an HTTPWebRequest to download pages from the internet, but these p开发者_StackOverflowages require a login, so you log in with the WebBrowser and it uses the resulting cookies to be able to download the actual page.


HttpWebRequest request = (HttpWebRequest) WebRequest.Create (myUri);
request.CookieContainer = new CookieContainer ();
request.CookieContainer.SetCookies (myUri, webBrowser1.Document.Cookie);

Edit: For your case, you may consider a NetworkCredential Object. It will work perfectly without any need for a WebBrowser or Cookies.

 WebRequest myWebRequest = WebRequest.Create(url);
    NetworkCredential networkCredential = new NetworkCredential(username, password);
    myWebRequest.Credentials = networkCredential;
0

精彩评论

暂无评论...
验证码 换一张
取 消