automate login using httpwebrequest problem


hi there,
i am trying to automate login using httpwebrequest it does all the work correctly but when i try to redirect to the welcome page with the cookie headers that i got from the last post it redirect me to login , this is my code, any help plz?

// making post with login data
PostData = "login_username=clude&secretkey=taamea&js_autodetect_results=1&just_logged_in=1";

Url = "http://webmail.cleanercorners.com/src/redirect.php";

sReferer = "http://webmail.cleanercorners.com/src/login.php";


webRequest = (HttpWebRequest)WebRequest.Create(Url);

webRequest.Headers["Accept-Language"] = "ar-eg"; //"en-us"; //ar-eg

//webRequest.ProtocolVersion = HttpVersion.Version11;

webRequest.AllowAutoRedirect = false;

webRequest.Referer = sReferer;

webRequest.KeepAlive = true;

//webRequest.ContentType = "";

webRequest.UserAgent = " Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";

webRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";

// making a post
ASCIIEncoding encoding = new ASCIIEncoding();

encodedPostData = encoding.GetBytes(PostData);

webRequest.Method = "POST";

webRequest.ContentType = "application/x-www-form-urlencoded";

webRequest.ContentLength = encodedPostData.Length;

Stream requestStream = null;

requestStream = webRequest.GetRequestStream();

requestStream.Write(encoding.GetBytes(PostData), 0, PostData.Length);

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

requestStream.Close();

// getting the cookies from the response
cookies = res.Headers["Set-Cookie"] ;

string[] sCookiesParts = cookies.Split(new char[2] { ';', ',' });

string sFormatedCookies = sCookiesParts[0] + ";" + sCookiesParts[2] + ";" + sCookiesParts[6];




//HttpCookie cookie1 = new HttpCookie("Cookie", sFormatedCookies);
//Response.Cookies.Add(cookie1);

// redirect with cookies
Response.AddHeader("Cookie", sFormatedCookies);

Response.Redirect("http://webmail.cleanercorners.com/src/webmail.php");
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories