Start New Discussion within our Web Development Community

Hello all

I having an issue in logging into a website using webRequest and WebResponse.
I thought let me reach out to experts by posting a question.

I am trying to login in and want to access the page after the login is successfull.
I used following code to do so. But somehow it failed

string poststring = string.Format("Username={0}&Password={1}", Username, Password);
byte[] postdata = Encoding.UTF8.GetBytes(poststring);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = postdata.Length;
webRequest.Credentials = new NetworkCredential(Username, Password);
Stream writer = webRequest.GetRequestStream();
writer.Write(postdata, 0, postdata.Length);
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

I dont know what to do when cookie gets added to my browzer. How can i use this cookie to access the other pages of that website after loging in. I want to do this using WebRequest and WebResponse .

This article has been dead for over six months. Start a new discussion instead.