neo
neo

Reputation: 197

Get/Set cookie with WebBrowser class C#

I need in some help about class "WebBrowser" in C#. How I can send a cookie with GetRequest and save a cookie from Response? Why this code don't work and how to correct error?

private void GetMail_Click(object sender, EventArgs e)
{
    webBrowser1.Document.Cookie = "https://signup.live.com/signup.aspx?mkt=ru-RU&lic=1";
    webBrowser1.Navigate("https://signup.live.com/signup.aspx?mkt=ru-RU&lic=1");
}

Upvotes: 3

Views: 6488

Answers (1)

Matas Vaitkevicius
Matas Vaitkevicius

Reputation: 61401

There's a method InternetSetCookie that can be called from WebBrowserControl, it should look something like this.

First you import the InternetSetCookie function:

[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetSetCookie(string UrlName, string CookieName, string CookieData);

and then you call it from your click handler.

private void GetMail_Click(object sender, EventArgs e)
{
    InternetSetCookie(url, "JSESSIONID", Globals.ThisDocument.sessionID); 
    webBrowser1.Navigate(url); 
}

Upvotes: 2

Related Questions