none
Login using WebRequest and WebResponse class in c#

    Question

  • 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


    markand


    Friday, August 23, 2013 10:11 AM

All replies

  • Hi MarkandBhatt,

    According to your description, the issue is more related to ASP.NET forum.

    To solve it ASAP, you can post it in the ASP.NET forum.

    ASP.NET forum:http://forums.asp.net/

    Regards,

    ZeTan 


    ALL FOR ONE AND ONE FOR ALL.

    Saturday, August 24, 2013 3:06 AM