reading-notes

View on GitHub

Sending form data

a client sends a request to a server , using the HTTP protocol. The server answers the request using the same protocol.

image

On the client side: defining how to send the data

The <form> element defines how the data will be sent. All of its attributes are designed to let you configure the request to be sent when a user hits a submit button.

The action attribute defines where the data gets sent.

The method attribute defines how data is sent Most common ways to perform a request :

The GET method

Since the GET method has been used, you’ll see the URL www.foo.com/?say=Hi&to=Mom appear in the browser address bar when you submit the form.

image

The POST method

When the form is submitted using the POST method, you get no data appended to the URL, and the HTTP request looks like so : POST / HTTP/2.0 Host: foo.com Content-Type: application/x-www-form-urlencoded Content-Length: 13 say=Hi&to=Mom

HTTP requests are never displayed to the user

your form data will be shown as follows in the Chrome Network tab. After submitting the form:

image

In the POST request the data didn’t app displayed to the user is the URL , so we usually use POST request for :

Code languages that you can used to create http request

sending files by HTTP :

Files are binary data whereas all other data is text data. Because HTTP is a text protocol, there are special requirements for handling binary data to send files by HTTP, you need to take three extra steps: