title: C# HttpClient Cookie and Session ID question
body: <p>went through a bit of reading material, and found for processes that only require input into simple forms, rather then browser automation, I was hearing about making requests and posts to the server with the information it expects with HTTPrequests. I figured I would give it a shot!</p>
  
  <p>I will try to get straight to the point here:</p>
  
  <pre><code>class Program
   {     
     private static System.Net.CookieContainer cookieContainer = new CookieContainer();
      private static HttpClientHandler clientHandler = new HttpClientHandler
      {
          AllowAutoRedirect = true,
          UseCookies = true,
          CookieContainer = cookieContainer
      };
  </code></pre>
  
  <p>So that is me attempting to get the Http client to use throughout the program. And when I get to my first login screen (I used fiddler to see what the form needed to post), I make a successful login with the post.</p>
  
  <p>I will show you the post method:  </p>
  
  <pre><code>         async static void PostRequest(string strUrl, 
            IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; queries)
      {
          HttpContent q = new FormUrlEncodedContent(queries);
          HttpResponseMessage response = await client.PostAsync(strUrl, q);
  
          HttpContent content = response.Content;
          string myContent = await content.ReadAsStringAsync();
  
          // Console.WriteLine(myContent);
          Console.WriteLine(response);
          Console.WriteLine(myContent);
          response.Dispose();
  
      }
  </code></pre>
  
  <p>My issue here, the next post I attempt to do is another form after you have been logged in. I again used Fiddler to figure out what the server was expected, and posted it to the appropriate URL, but when I print each step of the process, its almost like it does not know the session or something. Fiddler showed me the cookie and session, and I thought it was being captured with the container and then it could be used throughout the rest of the program as I request/post to pages on the server.</p>
  
  <p>Am I missing anything? You all won't be able to go the the actual webpage, but I can explain what fiddler is showing under the cookies tab: Says the request sent 2685 bytes of cookie data then a huge set of random letters and numbers and a few values that look specific to my login, then I also see another random set of numbers and letters that are called session id.</p>
  
  <p>So to sum up what my question is, am I misunderstanding what CookieContainer does? My assumption was throughout all the requests or posts I make with this HttpClient it would know it was the session from my initial login.</p>
  
  <p>Thoughts, ideas, links I may not have yet discovered, are all appreciated :).</p>
  
  <p>Thanks guys!</p>