1,105,644 Community Members

Login using WebRequest and WebResponse class in c#

Member Avatar
MARKAND911
Junior Poster
148 posts since Nov 2008
Reputation Points: -1 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
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 .

Member Avatar
pritaeas
mod_pritaeas
11,315 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

I think the CookieContainer class might be what you're looking for.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article