Submit a HTML Form programmatically

D

Darran

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
N

Nicholas Paldino [.NET/C# MVP]

Darran,

Or, you can just use the UploadValues method on the WebClient class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top