By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,673 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,673 IT Pros & Developers. It's quick & easy.

Submit a HTML Form programmatically

P: n/a
Hi

I want to be able to retrieve the data from a given URL, fill in the
necessary form fields and submit the form back to the server, all from
within a Windows Application. I can retrieve the HTML from the page,
using the HttpWebRequest class but that is where I have become stuck.
These are the remaining items I would like to be able to do

1 Fill in the necessary fields on the form.
2 Submit the data back to the server
3 Retrieve the response from the server and start the loop again.

Any ideas?
Thanks

Darran
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Darran,

You will use the HttpWebRequest class just as you did before. However,
this time, you need to set the Method property to "POST", which will
indicate that you are posting data. Also, you will have to call
GetRequestStream, and write to the stream the content of the forms data.

First, you need to set the ContentType property to
"application/x-www-form-urlencoded".

Then, you have to find the ids of the controls that are going to send
information. You will have to then write to the Stream returned by
GetRequestStream the values in the following manner:

name1=value1&name2=value2

You have to make sure that the values are encoded correctly, as certain
characters are not allowed.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Darran" <Da***********@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi

I want to be able to retrieve the data from a given URL, fill in the
necessary form fields and submit the form back to the server, all from
within a Windows Application. I can retrieve the HTML from the page,
using the HttpWebRequest class but that is where I have become stuck.
These are the remaining items I would like to be able to do

1 Fill in the necessary fields on the form.
2 Submit the data back to the server
3 Retrieve the response from the server and start the loop again.

Any ideas?
Thanks

Darran

Nov 13 '05 #2

P: n/a
Darran,

Or, you can just use the UploadValues method on the WebClient class.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Darran" <Da***********@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi

I want to be able to retrieve the data from a given URL, fill in the
necessary form fields and submit the form back to the server, all from
within a Windows Application. I can retrieve the HTML from the page,
using the HttpWebRequest class but that is where I have become stuck.
These are the remaining items I would like to be able to do

1 Fill in the necessary fields on the form.
2 Submit the data back to the server
3 Retrieve the response from the server and start the loop again.

Any ideas?
Thanks

Darran

Nov 13 '05 #3

P: 3
I have to do a similar thing: fill 2 textbox with user and password, can you explain how to do it?
Jun 12 '06 #4

P: 3
Uhm.. Nobody knows? :(
Jun 12 '06 #5

P: 3
Expand|Select|Wrap|Line Numbers
  1.                         ASCIIEncoding encoding = new ASCIIEncoding();
  2.                         string postData = "username=" + strUser + "&password=" + strPass + "&login_button.x=0&login_button.y=0";
  3.                         byte[] data = encoding.GetBytes(postData);
  4.                         // Prepare web request...
  5.                         HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("urlofthesite");
  6.                         myRequest.Method = "POST";
  7.                         myRequest.ContentType = "text/html";
  8.                         myRequest.ContentLength = data.Length;
  9.                         Stream newStream = myRequest.GetRequestStream();
  10.                         // Send the data.
  11.                         newStream.Write(data, 0, data.Length);
  12.                         newStream.Close();
  13.  
I find out this code, but how can i check if i'm logged in succesfully or not?
Jun 13 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.