title: C# Get Cookies from server response provided on data POST
body: <p>I can't get my head around this (login) problem:
  1) I post some data
  2) Server reacts and generate response with some cookies in headers (Set-Cookie)
  3) I want to store that cookies so I can later use them to generate more requests</p>
  
  <p>My C# code looks like this:</p>
  
  <pre><code>byte[] buffer = Encoding.ASCII.GetBytes(data_to_post);
  
  HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
  WebReq.Method = "POST";
  WebReq.ContentType = "application/x-www-form-urlencoded";
  WebReq.ContentLength = buffer.Length;
  
  Stream PostData = WebReq.GetRequestStream();
  PostData.Write(buffer, 0, buffer.Length);
  PostData.Close();
  
  HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
  Stream Answer = WebResp.GetResponseStream();
  StreamReader _Answer = new StreamReader(Answer);
  WebResp.Close(); // I want cookies here! But there is no cookies :(
  </code></pre>
  
  <p>Thing is that WebResp does have the "Set-Cookie" header with values. Before I will run and parse headers I wonder why Cookies object is not propagated (0 cookies) and filled with values from header.</p>
  
  <p>Anyone have idea ?</p>