title: C# Send POST request and receive 303 statuscode
body: <p>I'm writing simple application which connects to webpage and receives specific data from document's body.</p>
  
  <p>I'm sending <code>HttpWebRequest</code> in this way:</p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://webpage.com/page1.php");
  request.Method = "POST";
  string postData = "some_post_data";
  byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  request.ContentType = "application/x-www-form-urlencoded";
  request.Referer = "http://webpage.com/";
  request.ContentLength = byteArray.Length;
  request.CookieContainer = new CookieContainer();
  request.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31";
  request.Headers.Add("Cookie", string.Format("sess_id={0}", UserInfo.SessionId));
  request.Headers.Add("Accept-Charset", "ISO-8859-2,utf-8;q=0.7,*;q=0.3");
  request.Headers.Add("Accept-Language", "pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4");
  request.Headers.Add("Accept-Encoding", "gzip");
  request.AutomaticDecompression = DecompressionMethods.GZip;
  
  Stream dataStream = request.GetRequestStream();
  dataStream.Write(byteArray, 0, byteArray.Length);
  dataStream.Close(); // *** [1] ***
  
  HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // *** [2] ***
  dataStream = response.GetResponseStream();
  response.Close();
  
  StreamReader reader = new StreamReader(dataStream);
  string responseFromServer = reader.ReadToEnd();
  </code></pre>
  
  <p>Fine! The request is ok, there is nothing magic. The point is, after <code>dataStream.Close();</code> (line [1]) I receive 303 status code, which means there will be redirect to another page. When I read response at point [2] I see new (redirected) page.</p>
  
  <p>All I want is to read headers before redirect. Is it possible anyway?</p>