title: facebook Web form login using HttpWebRequest (c#)
body: <p>Im getting stuck with my code. Im just trying to access facebook home via c# and httpweb request.</p>
  
  <p>I'm trying to do the login stuff with:</p>
  
  <pre><code>System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("https://www.facebook.com/login.php?login_attempt=1");
  string s = "email=XXXXX@mymail.com&amp;pass=YYYYY";
  
  CookieContainer cookies = new System.Net.CookieContainer();
  
  request.Method = "POST";
  request.AllowAutoRedirect = false;
  request.MaximumAutomaticRedirections = 1;
  request.ContentType = "application/x-www-form-urlencoded";
  request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
  request.KeepAlive = true;
  request.Timeout = 10000;
  request.CookieContainer = cookies;
  request.ContentLength = s.Length;
  
  byte[] bytes = Encoding.UTF8.GetBytes(s);
  request.ContentLength = bytes.Length;
  
  System.IO.Stream requestStream = request.GetRequestStream();
  requestStream.Write(bytes, 0, bytes.Length);
  requestStream.Close();
  
  Console.WriteLine("\n Cookies count is :{0}", cookies.Count); //0, obviously
  //get response and print it
  
  System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
  System.IO.Stream response_stream = response.GetResponseStream();
  System.IO.StreamReader sr = new System.IO.StreamReader(response_stream);
  string response_string = sr.ReadToEnd();
  
  Console.WriteLine("\n Cookies count is :{0}", cookies.Count);
  </code></pre>
  
  <p>OK. At this point two things happened:  </p>
  
  <ol>
  <li>I have 3 cookies stored (cookies.count)</li>
  <li>HTML response from FB says that I need to activate cookies in my browser.</li>
  </ol>
  
  <p>My questions are:  </p>
  
  <ol>
  <li>Is the code above correct? If so, why am I getting the cookie message from FB?</li>
  <li>If I now want to navigate to my FB home, should I create another request to home URL using the cookies store filled previously?</li>
  </ol>