How to post HTML Form Data to the Server? [C#/.NET Code]
To post HTML form data to the server in URL-encoded format using C#/.NET, you need to make an HTTP POST request to the server and provide the HTML form data in the body of the C#/.NET POST message. You also need to specify the data type using the Content-Type: application/x-www-form-urlencoded request header. HTML form data can also be sent to the server using the HTTP GET method. In this case, HTML form data is passed in the URL as key/value pairs separated by ampersands (&), and keys are separated from values by equality (=). The C#/.NET code was automatically generated for the POST HTML Form example.
Submitting HTML Forms over HTTP using with C#/.NET
In HTTP, there are two ways to send HTML forms to the server, both from browsers and from C#/.NET code.
1. Using the media type application/x-www-form-urlencoded. This type of media is mainly used to send short HTML forms in the form of key-value pairs, for example when authorizing a user using login/password forms.
HTML Login Form Request Example
POST /login HTTP/1.1
2. Using media type multipart/form-data. This type of media is used by browsers when uploading binary data to a server (for example, when uploading multiple images). In this case, the form data is formatted as a series of parts separated by MIME boundaries.
In some cases, you can submit form data using the HTTP GET method. The form data is passed to the server as a series of name/value URL parameters, , and you are limited to the maximum length of the URL. For browsers the limit is around 2000 characters (browser dependent) for C#/.NET code, there is no such limit, but your server may have its own limits. For example, the maximum length of an Apache URL is 8177 characters. Submitting HTML forms using the HTTP GET method is less secure because you are passing data in URL parameters.
Example of Sending an HTML Form using HTTP GET Method
GET /login?login=my_login&password=my_passowrd HTTP/1.1
Generate code snippets for C#/.NET and other programming languages