I'm trying to log onto a website by providing my (correct) username and password.
Here's the 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);
But, surprise surprise, it's not logging on. I just get the logon page back.
Any help would be appreciated and this is doing my head in now!!
Thanks,
Jim
For completeness here is my WebClient class -
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;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…