I am trying to get this application to login in order to gather specific data from within the members area. This is the first time I have done this and I am not sure whats wrong.
The site passes the login like this:
http://www.example.com/Ajax/Users_Login.asp ?UserName=NAME& UserPsw=PASS&Re memberMe=1&LogI nLocation=0&Bac kUrl=0
When this page is loaded it displays a xml file with a welcome message. When I retrieve the requested page it acts like it was not logged in. Any help would be greatly appreciated!
The site passes the login like this:
http://www.example.com/Ajax/Users_Login.asp ?UserName=NAME& UserPsw=PASS&Re memberMe=1&LogI nLocation=0&Bac kUrl=0
When this page is loaded it displays a xml file with a welcome message. When I retrieve the requested page it acts like it was not logged in. Any help would be greatly appreciated!
Code:
string loginUri = "http://www.example.com/Ajax/Users_Login.asp";
string loginData = "?UserName=NAME&UserPsw=PASS&RememberMe=1&LogInLocation=0&BackUrl=0";
string requestUri = "http://www.example.com/";
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(loginUri);
req.CookieContainer = cookieContainer;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] loginDataBytes = encoding.GetBytes(loginData);
req.ContentLength = loginDataBytes.Length;
Stream stream = req.GetRequestStream();
stream.Write(loginDataBytes, 0, loginDataBytes.Length);
stream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
req = (HttpWebRequest)HttpWebRequest.Create(requestUri);
req.CookieContainer = cookieContainer;
req.Method = "GET";
res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
textBox1.Text = sr.ReadToEnd();