title: WebClient website login
body: <p>I have difficulties logging in to a webpage (http://hurt.prosto.pl); all the time it returns to the login page source... Any idea how to fix it?</p>
  
  <pre><code>var loginData = new NameValueCollection();
  loginData.Add("username", username);
  loginData.Add("password", password);
  
  var client = new CookieAwareWebClient();
  client.BaseAddress = @"http://hurt.prosto.pl/accounts/login/?next=/hurt/";
  client.UploadValues("http://hurt.prosto.pl/accounts/login/?next=/hurt/", "POST", loginData);
  
  // now you are logged in and can request pages    
  string htmlSource = client.DownloadString("http://hurt.prosto.pl/hurt/myorders/--/category/all1/");
  webBrowser2.DocumentText = htmlSource;
  </code></pre>
  
  <p>This is my CookieAwereWebClient class:</p>
  
  <pre><code>namespace HTMLParser
  {
      internal class CookieAwareWebClient : WebClient
      {
          private CookieContainer cookie = new CookieContainer();
  
          protected override WebRequest GetWebRequest(Uri address)
          {
              WebRequest request = base.GetWebRequest(address);
              if (request is HttpWebRequest)
              {
                  (request as HttpWebRequest).CookieContainer = cookie;
              }
              return request;
          }
      }
  }
  </code></pre>