title: C# How to keep connection alive while parsing html
body: <p>I'm trying to create a little script, that lets you login automatically to a php website. 
  When I looked at the POST script that is being sent through https, I realized that there is a hidden inputform with a hash string (in the login form hidden with css visibility) which is being send in the data form with the email + password
  Example:</p>
  
  <pre><code>login=USERNAME&amp;passwort=PASSWORD&amp;loginhash=1b9f29d68152619b469c3744de3a1f54
  </code></pre>
  
  <p>So actually I would need to do a simple GET action before the post to parse the string out and then do the POST with the loginhash but how do I keep that connection alive without getting a new hash that is not matching anymore?</p>
  
  <pre><code>//GET
      WebRequest req = WebRequest.Create(url);
      WebResponse resp = req.GetResponse();          
      using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
      {
      reqHtml = sr.ReadToEnd();
      }
      cookieHeader = resp.Headers["Set-cookie"];
  
  //Parsing html and storing to var loginhash
  
  //POST
      string formData = string.Format("login={0}&amp;loginhash={1}&amp;passwort={2}", "USERNAME", loginhash, "PASSWORD");
      req.ContentType = "application/x-www-form-urlencoded";
      req.Method = "POST";
      req.Headers.Add("Cookie", cookieHeader);
      byte[] bytes = Encoding.ASCII.GetBytes(formData);
      req.ContentLength = bytes.Length;
      using (Stream os = req.GetRequestStream())
      {
          os.Write(bytes, 0, bytes.Length);
      }
  
      using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
      {
          pageSource = sr.ReadToEnd();
      }
  </code></pre>
  
  <h3>Update:</h3>
  
  <p>Realized, that my theory is actually wrong as I sent two GET's with curl so that curl would pipeline/reuse the connection before. At the end there were still two different hashes in the responses. Maybe the Hash is just a distraction ?</p>