Reputation: 6446
I need to visit a URL, find a specific text box in said page - fill it with data and then submit a form.
How can I accomplish this in C#?
P.S. Innocent intentions.
Upvotes: 3
Views: 297
Reputation: 3481
if you visit the page in a browser and do the stuff you need manually with fiddler2 installed and activated you can see which requests get sent to the webserver.
All you need to do is to replicate those requests (form posts) using for example the WebRequest class or the WebClient class in the .net framework.
WatiN is also an alternative.
Upvotes: 0
Reputation: 8226
You'd be best looking at the WebRequest
class (System.Net).
You'll want to look at the POST Method to post a form (click the submit button with the required fields completed).
Example:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
There is a nice tutorial and lots of information on MSDN here. (Continuation of above source code)
Upvotes: 5