Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>use cookie collection to grab cookies, I've write something similar this month and I can share you some sample code:</p> <pre><code> static string GetFromServer(string URL, ref CookieCollection oCookie) { //first rquest // Create a request for the URL. HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL); request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"; request.AllowAutoRedirect = false; // If required by the server, set the credentials. //request.Credentials = CredentialCache.DefaultCredentials; request.CookieContainer = new CookieContainer(); if (oCookie != null) { foreach (Cookie cook in oCookie) { request.CookieContainer.Add(cook); } } // Get the response. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); foreach (Cookie cook in response.Cookies) { oCookie.Add(cook); } // Display the status. while (response.StatusCode == HttpStatusCode.Found) { response.Close(); request = (HttpWebRequest)HttpWebRequest.Create(response.Headers["Location"]); request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"; request.AllowAutoRedirect = false; request.CookieContainer = new CookieContainer(); if (oCookie != null) { foreach (Cookie cook in oCookie) { request.CookieContainer.Add(cook); } } response = (HttpWebResponse)request.GetResponse(); foreach (Cookie cook in response.Cookies) { oCookie.Add(cook); } } Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. Console.WriteLine(responseFromServer); // Clean up the streams and the response. reader.Close(); response.Close(); return responseFromServer; } </code></pre> <p>Now you got cookies, and you just need to set it to the webBrowser control, import this method:</p> <pre><code> [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData); </code></pre> <p>and call this after you got cookies:</p> <pre><code> string cookie_string = string.Empty; foreach (Cookie cook in cookieCon) { cookie_string += cook.ToString() + ";"; InternetSetCookie(url, cook.Name, cook.Value); } webBrowser1.Navigate(url, "", null, "Cookie: " + cookie_string + Environment.NewLine); </code></pre> <p>Please be aware of that this is just my test code and mainly was copied from msdn so it may buggy and you may need more exception handling</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload