Note that there are some explanatory texts on larger screens.

plurals
  1. POretrieve and set cookies
    primarykey
    data
    text
    <p>I'm trying to connect to a website that uses cookies. My login is as follows:</p> <pre><code> private void button1_Click(object sender, EventArgs e) { try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseurl); req.Referer = referer; req.AllowAutoRedirect = true; req.KeepAlive = true; req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; byte[] postbuf = Encoding.ASCII.GetBytes(login); req.ContentLength = postbuf.Length; Stream rs = req.GetRequestStream(); rs.Write(postbuf, 0, postbuf.Length); rs.Close(); cookie = req.CookieContainer = new CookieContainer(); WebResponse resp = req.GetResponse(); string s = ""; foreach (Cookie c in cookie.GetCookies(req.RequestUri)) { s += ("Cookie['" + c.Name + "']: " + c.Value); } textBox1.Text = s; resp.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } </code></pre> <p>The cookie has 2 keys with values. Then I try to send a post request to the website as follows:</p> <pre><code> private void button2_Click(object sender, EventArgs e) { try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(search); req.Referer = referer; req.AllowAutoRedirect = true; req.KeepAlive = true; req.CookieContainer = cookie; StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream()); if (reader != null) { string data = reader.ReadToEnd(); reader.Close(); textBox1.Text = data; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } </code></pre> <p>But I get an error that it cannot authenticate. When I login using firefox, I see that the cookie contains much more entries.</p> <p>What is wrong with my code?</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.
 

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