title: C# - Cookie Management
body: <p>I asked a question on here earlier and got some fantastic responses. I've since been diddling Visual C# and ran into a bit of a problem.</p>
  <p><a href="http://binarywatch.biz/forms/cookietest.php" rel="nofollow noreferrer">Here</a> I made a simple page that sets a cookie.</p>
  <p>If you go to it and then refresh, it'll see if there's a cookie present and change the output html.</p>
  <p>Now, I want my C# program to fetch a page, get a cookie and then re-visit the page again with the cookie that is set, so that my page presents me the &quot;updated&quot; message. I accomplished phase one via:</p>
  <pre><code>    private void button1_Click(object sender, RoutedEventArgs e)
      {
          WebRequest request = WebRequest.Create(&quot;http://www.binarywatch.biz/forms/cookietest.php&quot;);
  
          request.Credentials = CredentialCache.DefaultCredentials;
          HttpWebResponse response = (HttpWebResponse)request.GetResponse();
          Stream dataStream = response.GetResponseStream();
          StreamReader reader = new StreamReader(dataStream);
          string responseFromServer = reader.ReadToEnd();
  
          MessageBox.Show(responseFromServer, &quot;Derp&quot;);
  
          reader.Close();
          dataStream.Close();
          response.Close();
      }
  </code></pre>
  <p>So at this point I have the page html but I'm a bit lost as to how to go about getting a cookie (Something to do with CookieContainer() ? ) and then making the page know that I have it (by adding it to the httpwebrequest somehow?)</p>
  <p>I tried googling it of course but a LOT of the answers I find are about ASP.NET / web programming and that's not what I need.</p>
  <p>PS. What's the difference between WebRequest and HttpWebRequest?</p>
  <p>I hope this isn't too noobish, I'm a bit stumped.</p>