I'm programmatically logging in to a website, using HttpWebRequest, POST method. The first time I successfully authenticate, via HttpWebResponse I receive cookie hash key. The second time I perform the same action, I don't receive it anymore.
Does that mean I'm already "Logged in", or does it store my session somewhere, I don't quite understand it, if someone could explain, thank you!
Here's my code and simply said, running this twice, do not return same cookie result.
HttpWebRequest http = (HttpWebRequest)WebRequest.Create("URL");
string cookie = string.Empty;
string values = "vb_login_username=" + username + "&vb_login_password=" + password + "securitytoken=guest&" + "cookieuser=checked&" + "do=login";
http.Method = "POST";
http.ContentType = "application/x-www-form-urlencoded";
http.ContentLength = values.Length;
CookieContainer cookies = new CookieContainer();
http.CookieContainer = cookies;
ServicePointManager.Expect100Continue = false;
using (var stream = new StreamWriter(http.GetRequestStream(), Encoding.ASCII))
{
stream.Write(values);
}
HttpWebResponse response = (HttpWebResponse)http.GetResponse();
foreach (var c in response.Cookies)
{
cookie = cookie + c.ToString() + ";";
}
return cookie;
Aucun commentaire:
Enregistrer un commentaire