开发者

Implementing OnSubmit with httpwebrequest

I am new to C# and just messing around with it myself, now, i have been trying to create a WinForm that can post some parameters in a webpage and do something something on the resultant webpage obtained. Now I have accomplished this on a page that uses POST method, But i am not able to do so with A webpage that has a html code like this :

<form method="post" action="test.asp" name=FrontPage_Form1 onsubmit="return FrontPage_Form1_Validator(this)">
      <div align="center"><center><p>
      <input name="name" size="8" maxlength=8><font color="#faebd7">---

Now i don't how How To implement this "ONSUBMIT" with HttpWebRequest..

This is my current Code :

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://cbseresul开发者_C百科ts.nic.in/aieee/cbseaieee.asp");
            request.Method = "POST";
            string r = "regno=" + rno.ToString();
            Bytes = Encoding.UTF8.GetBytes(r);

      request.ContentLength = Bytes.Length;
      request.ContentType = "application/x-www-form-urlencoded";

        RequestStream = request.GetRequestStream();
        RequestStream.Write(Bytes, 0, Bytes.Length);
        RequestStream.Close();

        Response = (HttpWebResponse)request.GetResponse();
        StreamReader ResponseStream = new StreamReader(Response.GetResponseStream(), Encoding.ASCII);
        string Result = ResponseStream.ReadToEnd();
        ResponseStream.Close();

But its not working, Any Help is greatly appreciated...


Try using Fiddler in order to understand what the page is sending and receiving from the server. Then make the request as it is shown in fiddler...

You can also use WebClient to open some pages or sending and receiving data from server.

There are some ways to click on buttons or links:

  1. Use a WebBrowser object in your app and Iterate through objects on the page by using SelectNextControl method of WebBrowser object and then sending Enter key like so: SendKeys.Send("{Enter}");

  2. Using JavaScript and invoking functions and reading elements using getElementById and some other methods

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜