title: C# WebClient Log onto Website
body: <p>I'm trying to log onto a website by providing my (correct) username and password.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>        string URL = @"https://www.t-mobile.co.uk/service/your-account/login/";
  
          string username = "a_user";
          string password = "a_password";
          //ServicePointManager.Expect100Continue = false;
  
          CookieAwareClient client = new CookieAwareClient();
  
  
          NameValueCollection postData = new NameValueCollection();
          postData.Add("username", username);
          postData.Add("password", password);
  
          byte[] response = client.UploadValues(URL,  postData);
  
          ASCIIEncoding enc = new ASCIIEncoding();
          string Source = enc.GetString(response);
  </code></pre>
  
  <p>But, surprise surprise, it's not logging on. I just get the logon page back.</p>
  
  <p>Any help would be appreciated and this is doing my head in now!!</p>
  
  <p>Thanks,
  Jim</p>
  
  <p>For completeness here is my WebClient class -</p>
  
  <pre><code>public class CookieAwareClient : WebClient
  {
      private CookieContainer m_container = new CookieContainer();
      protected override WebRequest GetWebRequest(Uri address)
      {
          WebRequest request = base.GetWebRequest(address);
          if (request is HttpWebRequest)
          {
              (request as HttpWebRequest).CookieContainer = m_container;
          }
          return request;
      }
  }
  </code></pre>