login to website from code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rama Jayapal
    New Member
    • Mar 2007
    • 24

    #1

    login to website from code

    i use the following code to login to a website

    but i dont achieve my purpose

    can anybody help me on this

    //code to request the page

    webRequest = HttpWebRequest. Create(url) as HttpWebRequest;

    webRequest.Prox y = proxy;

    webRequest.Meth od = "GET";

    webRequest.Acce pt = "*/*";

    webRequest.User Agent = userAgent;

    webRequest.Cook ieContainer = cookies;

    //Request and get the response

    webResponse = webRequest.GetR esponse() as HttpWebResponse ;

    //Update the cookies

    cookies.Add(web Response.Cookie s);

    response = new StreamReader(we bResponse.GetRe sponseStream()) ;

    //code to postdata

    webRequest = HttpWebRequest. Create(url) as HttpWebRequest;

    webRequest.Prox y = proxy;

    webRequest.Meth od = "POST";

    webRequest.Acce pt = "*/*";

    webRequest.User Agent = userAgent;

    webRequest.Cook ieContainer = cookies;

    webRequest.Prot ocolVersion = HttpVersion.Ver sion10;

    webRequest.Cont entType = "applicatio n/x-www-form-urlencoded";

    webRequest.Cont entLength = postData.Length ;

    using (StreamWriter writer = new StreamWriter(we bRequest.GetReq uestStream()))

    {

    writer.Write(po stData);

    writer.Close();

    }

    //Request and get the response

    webResponse = webRequest.GetR esponse() as HttpWebResponse ;

    //Update the cookies

    cookies.Add(web Response.Cookie s);

    response = new StreamReader(we bResponse.GetRe sponseStream()) ;

    can anybody help on where the mistake is?



    thanks

    Rama
Working...