Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Requests in C#

Tags:

c#

http

asp.net

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.

like image 515
Erez Avatar asked Jun 17 '26 14:06

Erez


1 Answers

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)

like image 116
Daniel May Avatar answered Jun 19 '26 03:06

Daniel May



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!