views:

455

answers:

1

Is there a way to read/write the cookies that a WebBrowser control uses?

I am doing something like this...

string resultHtml;
HttpWebRequest request = CreateMyHttpWebRequest(); // fills http headers and stuff
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
    resultHtml = sr.ReadToEnd();
}
WebBrowser browser = new WebBrowser();
browser.CookieContainer = request.CookieContainer; // i wish i could do this :(
browser.NavigateToString(resultHtml);  
+1  A: 

the webbrowser control uses WinInet for networking, specifically the InternetSetCookie(Ex) and InternetGetCookie(Ex) functions. There isn't a WinInet wrapper in .et, but you can p-invoke.

Sheng Jiang 蒋晟
+1, I didn't know about these APIs... could prove useful someday !
Thomas Levesque