title: C# : How to sign in and keep it valid and make another webrequest?
body: <pre class="lang-cs prettyprint-override"><code>private void button1_Click(object sender, EventArgs e)
  {
      string userName = textBox1.Text;
      string password = textBox2.Text;
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.youmint.com/LoginVerification.php?name="+userName+"&amp;pass="+password+"&amp;agreement=true&amp;checkvalue=true");
      request.Method = "GET";
      request.KeepAlive = true;
      request.Headers.Add("Keep-Alive: 300");
      WebResponse response = request.GetResponse();
      Stream dataStream = response.GetResponseStream();
      StreamReader reader = new StreamReader(dataStream);
      string responseFromServer = reader.ReadToEnd();
      if (responseFromServer.Equals(""))
          MessageBox.Show("Successfully logged in!!");
      else if (responseFromServer.Equals("1"))
          MessageBox.Show("Login failed!");
      request = (HttpWebRequest)WebRequest.Create("http://www.youmint.com/FreeSms.html");
      response = request.GetResponse();
      dataStream = response.GetResponseStream();
      reader = new StreamReader(dataStream);
      responseFromServer = reader.ReadToEnd();
      /*secret code :P */
      reader.Close();
      dataStream.Close();
      response.Close();
   }
  </code></pre>
  
  <p>So, that's my code... The first webrequest logs into the website. It works fine in the browser and returns 1 if the login is not correct. Then the second one is a normal webrequest to a webpage of the same website. But the login is already gone and the response I get is what I get if I'm not logged in! Can someone please tell me what I'm doing wrong? How do I keep it alive? Do I have to use an invisible webbroswer control or something like that?</p>