locked
please help , problem with HttpWebRequest RRS feed

  • Question

  • User-663248805 posted

    Well I am trying to log in to a form authentication page.

    ok i successfuly loged in and it work.

    Now the problem is i can not send the second request to that page to click on a link in logged in page.

     

     Do i need to create another reuqest for it or can i use the old one?

    here is the error i get:

    Cannot send a content-body with this verb-type. 

     here is my code.

     

    private void button2_Click(object sender, RoutedEventArgs e)

    {

    string loginurl = "http://localhost/login.aspx";

    HttpWebRequest myreq = (HttpWebRequest)WebRequest.Create(loginurl);

    string postData = "some data for login in";

    string ClickButton = "click the button on logged in page";

    CookieContainer cookie = new CookieContainer();

    myreq.CookieContainer = cookie;

    myreq.ContentType =
    "application/x-www-form-urlencoded";

    myreq.Method = WebRequestMethods.Http.Post;

     

    // Send the login information to server

    byte[] bytearray = Encoding.UTF8.GetBytes(postData);Stream datastream = myreq.GetRequestStream();

    datastream.Write(bytearray, 0, bytearray.Length);

    datastream.Close();

     

    // Send the order to click a button on logged in page

    byte[] bytearray1 = Encoding.UTF8.GetBytes(ClickButton);Stream datastream1 = myreq.GetRequestStream();

    datastream1.Write(bytearray1, 0, bytearray1.Length);

    datastream1.Close();

    HttpWebResponse wr = (HttpWebResponse)myreq.GetResponse();

    }

    Tuesday, March 3, 2009 9:42 AM

All replies

  • User-206222649 posted

    I'm confused by what your trying to do here. Are you trying to postback to the login page and force a redirect?

    If so you should just do a Server.Transfer.

    Also your comment "send login information to the server"

    Your already at the server so what are you trying to do here exactly?

    Tuesday, March 3, 2009 10:25 AM
  • User-663248805 posted

    Hi Evan,

    let me put it that way. I want to log in to a web site using my windows form app. then click on a button after loging in.

    here is the code for loging in.

    private void button2_Click(object sender, RoutedEventArgs e)

    {

    string loginurl = "http://localhost/login.aspx";

    HttpWebRequest myreq = (HttpWebRequest)WebRequest.Create(loginurl);

     

    string postData = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMT3D&Login2%24UserName=test&Login2%24Password=test&Login2%24LoginButton=Log+In&__EVENTVALIDATION=%2FwEWBmbqq";

     

    CookieContainer cookie = new CookieContainer();

    myreq.CookieContainer = cookie;

    myreq.ContentType = "application/x-www-form-urlencoded";

    myreq.Method = WebRequestMethods.Http.Post;

     

    byte[] bytearray = Encoding.UTF8.GetBytes(postData);Stream datastream = myreq.GetRequestStream();

    datastream.Write(bytearray, 0, bytearray.Length);

    datastream.Close();

    HttpWebResponse wr = (HttpWebResponse)myreq.GetResponse();

    }

    and it work i can log in and it redirect me to members.aspx page. but now how to click on a button on that members page names button3?

    Wednesday, March 4, 2009 4:08 AM