title: Using BrowserSession and HtmlAgilityPack to login to Facebook through .NET
body: <p>I'm trying to use Rohit Agarwal's <a href="http://refactoringaspnet.blogspot.com/2010/04/using-htmlagilitypack-to-get-and-post.html" rel="noreferrer">BrowserSession</a> class together with HtmlAgilityPack to login to and subsequently navigate around Facebook.</p>
  
  <p>I've previously managed doing the same by writing my own HttpWebRequest's. However, it then only works when I manually fetch the cookie from my browser and insert a fresh cookie-string to the request each time I'm doing a new "session". Now I'm trying to use BrowserSession to get smarter navigation.</p>
  
  <p>Here's the current code:</p>
  
  <pre><code>BrowserSession b = new BrowserSession();
  
  b.Get(@"http://www.facebook.com/login.php");
  b.FormElements["email"] = "some@email.com";
  b.FormElements["pass"] = "xxxxxxxx";
  b.FormElements["lsd"] = "qDhIH";
  b.FormElements["trynum"] = "1";
  b.FormElements["persistent_inputcheckbox"] = "1";
  
  var response = b.Post(@"https://login.facebook.com/login.php?login_attempt=1");
  </code></pre>
  
  <p>The above works fine. Trouble comes when I try to use this BrowserSession again to fetch another page. I'm doing it this way since BrowserSession saves the cookies from the last response and inserts them into the next request, thus I should not have to manually inser cookiedata fetched from my browser anymore.</p>
  
  <p>However, when I try to do something like this:</p>
  
  <pre><code>var profilePage = b.Get(@"https://m.facebook.com/profile.php?id=1111111111");
  </code></pre>
  
  <p>the doc I get back is empty. I would appreciate any input on what I'm doing wrong.</p>