Sending Data with a POST Request5:57 with Chris Ramacciotti
There are many times in which HTTP is used to send a request whose purpose is to modify data on the server. POST requests are used for this purpose, and are constructed a bit differently than GET requests that are sending data. In a POST request, data is sent in the request payload instead of in the URI. This video shows you exactly how this is accomplished.
The UTF-8 character encoding is one in which every character in the Unicode Character Set can be represented with anywhere from 1 to 4 bytes.
In general, the character encoding of a submitted form is UTF-8 by default. In the video, all the characters that were part of the payload can be represented with 1 byte (8 bits). This is because they're all part of the Basic Latin Characters. See for yourself by looking at the Basic Latin Characters and finding all the ones from our POST request payload in the list:
Since each character in that payload will take up exactly one byte, counting the bytes is equivalent to counting the characters.
What happens if you use a character outside of Basic Latin? For example, consider the scenario that your payload instead looks like this:
The Greek capital sigma cannot be represented with one byte (it actually takes two). What your browser will do upon submitting a form with a
Σ is substitute a URL-encoded version, which in the case of the Greek capital sigma is
%CE%A3. So, the HTTP POST payload becomes the following:
Therefore, when the content-length header is calculated with this URL-encoded version, it has a value of 17, which is what will be included in the HTTP POST request.
You need to sign up for Treehouse in order to download course files.Sign up