title: WebClient/HttpRequest Navigating To Page After Login
body: <p>I want to login to a website using a webclient or httpwebrequest, after i'm logged in i want to navigate to a page in the site.<br>
  so i know how to post data and to login, my problem is with the navigation after the login,<br>
  it redirect me to the login page, i know it has to do with the cookies, but i dont understand what i'm doing worng... here is my code -> it is taken from another answear on stackoverfllow... (http://stackoverflow.com/questions/8425593/c-sharp-httpwebrequest-post-login-to-facebook) </p>
  
  <pre><code>        string getUrl = "somesite.com";
          CookieCollection cookies = new CookieCollection();
          HttpWebRequest request = (HttpWebRequest)WebRequest.Create(getUrl);
          request.CookieContainer = new CookieContainer();
          request.CookieContainer.Add(cookies);
          HttpWebResponse response = (HttpWebResponse)request.GetResponse();
          cookies = response.Cookies;
  
          string getUrl2 = "somepage.login.com";
          string postData = String.Format("username={0}&amp;userpassword={1}", "foo", "foofoo");
  
          HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl2);
          getRequest.CookieContainer = new CookieContainer();
          getRequest.CookieContainer.Add(cookies);
  
          getRequest.Method = WebRequestMethods.Http.Post;
          getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
          getRequest.AllowWriteStreamBuffering = true;
          getRequest.ProtocolVersion = HttpVersion.Version11;
          getRequest.AllowAutoRedirect = true;
          getRequest.ContentType = "application/x-www-form-urlencoded";
  
          byte[] byteArray = Encoding.ASCII.GetBytes(postData);
          getRequest.ContentLength = byteArray.Length;
          Stream newStream = getRequest.GetRequestStream(); 
          newStream.Write(byteArray, 0, byteArray.Length); 
          newStream.Close();
  
          HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
          using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
          {
              string sourceCode = sr.ReadToEnd();
          }
          //untill here it works fine i'm logged in....
  
  
          HttpWebRequest getRequest2 = (HttpWebRequest)WebRequest.Create("a page on the site..");
          getRequest2.CookieContainer = new CookieContainer();
          getRequest2.CookieContainer.Add(cookies); 
          HttpWebResponse getResponse2 = (HttpWebResponse)getRequest2.GetResponse();
          cookies = getResponse2.Cookies;
  
          using (StreamReader sr = new StreamReader(getResponse2.GetResponseStream()))
          {
              string sourceCode = sr.ReadToEnd();
          }
          //here it rediects me to login page
  </code></pre>
  
  <p>any suggestions> what i'm doing wrong</p>