0

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 http://www.mbhatt.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();
cookies.Add(webResponse.Cookies);

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 .

2
Contributors
1
Reply
11
Views
3 Years
Discussion Span
Last Post by pritaeas
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.