Hallo,

     I'm trying to write a application that automaticall fills in the
input fields of a webform and let the webform process this request.
More concreat suppose that you have a webform with two input fields and
a submit button. If you fill in the fields and press the submit button
some processing is done at the webserver, I want to make a application
that replace the browser and automate the filling in of the form. I use
HttpWebRequest to send a POST request to the webform and get the response
back. The webform seems to receive the request with the correct date
(verified with the Page.Request property on the Page_Load delegate, but it
will not issue a click event for the button, so no processing is done at
the webserver, how can I ensure that my client application force the 'click'
on the submit button. The code at the client application that I tried for the
moment is.

StringBuilder result=new StringBuilder();
StreamReader reader;
string send=String.Format("TextBoxFirst={0}&TextBoxSecond={1}&Button1=Ok",
     textBoxFirstInput.Text,
     textBoxSecondInput.Text);
// TextBoxFirst is the id of the first input field
// TextBoxSecond is the id of the second input field
// Buton1 is the Submit button

// Send the post
Stream writer;
req=(HttpWebRequest) WebRequest.Create(textBoxURL.Text);
req.Method="POST";
    req.ContentType="application/x-www-form-urlencoded";
req.ContentLength=send.Length;

req.Accept="text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1";
req.KeepAlive=true;
req.SendChunked=false;
req.Expect="";
req.Referer=textBoxURL.Text;
req.UserAgent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0rc2)
Gecko/20020510";
writer=req.GetRequestStream();
    writer.Write(Encoding.ASCII.GetBytes(send),0,send.Length);
writer.Close();
// Use the response to get the result of the post
resp=(HttpWebResponse) req.GetResponse();
reader=new StreamReader(resp.GetResponseStream(),Encoding.ASCII);
while (reader.Peek()!=-1)
{
  result.Append(reader.ReadLine());
};
textBoxResult.Text=result.ToString();
    reader.Close();
    resp.Close();

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to