Tuesday, 13 August 2013

Failed to log in to imdb through c#?

Failed to log in to imdb through c#?

I'm working on a project that needs to connect to IMDb and login the user
to retrieve some user data..
String formUrl = @"https://secure.imdb.com/register-imdb/login?#";
String user = username;
String pass = password;
String fromParams =
string.Format("49e6c={0}&login={1}&password={2}", _49e6c, user,
pass);
String cookieHeader;
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(formUrl);
req.ContentType = "text/html; charset=utf-8";
req.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(fromParams);
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}
try
{
HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
String isLoggedInSuccessfully = resp.StatusCode.ToString();
cookieHeader = resp.Headers["Set-cookie"];
MessageBox.Show("Status> " + isLoggedInSuccessfully);
using (StreamReader sr = new
StreamReader(resp.GetResponseStream()))
{
String pageSource = sr.ReadToEnd();
}
MessageBox.Show("Cookie Header> " + cookieHeader);
}
catch (Exception ex)
{
MessageBox.Show("Error> " + ex.Message);
}
the status is always 'OK', from my search I found that a successful login
has the status of 'FOUND' ?
so any idea why my code is not working ?

No comments:

Post a Comment