I’m trying to connect to another user page after I logged in using HttpWebRequest. But when I try it, it connects as not logged in. Does it have to do with cookies?
req = (HttpWebRequest)HttpWebRequest.Create("http://www.elitepvpers.com/forum/login.php?do=login");
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1";
req.Method = "POST";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req.Headers.Add("Accept-Language: tr-tr,tr;q=0.8,en-us;q=0.5,en;q=0.3");
req.KeepAlive = true;
req.Referer = "Referer: http://www.elitepvpers.com/theblackmarket/treasures/";
req.ContentType = "application/x-www-form-urlencoded";
string id = "username";
string pw = "*****";
StreamWriter sw = new StreamWriter(req.GetRequestStream());
sw.Write("vb_login_username=" + id + "&vb_login_password=" + pw + "&cookieuser=1&s=&securitytoken=1342962102-8aa76183509ebade0188ac49c3c84470ff2aabba&do=login&vb_login_md5password=&vb_login_md5password_utf=");
response = (HttpWebResponse)req.GetResponse();
Here this code solves the problem, you should add an CookieContainer to your request to handle the session. The site returned a html containning “Thank you for logging in, eferek”, and now the sessionID is stored in our CookieContainer, so every time you create a new request use the same CookieContainer and you will have the same session at the site.