First of all it is good to understand HTTP as a series of format conventions to be used over a common TCP connection. In principle it’s a protocol stateless where you basically send one text and get another back.
In other words, HTTP does not process anything, but sets a format. It is the responsibility of the application that meets the request to process the data, and provide a response consistent with the protocol.
To Wikipedia even has a reasonable definition of HTTP, but I will try to highlight the most relevant points for the question in a simple way right after.
If you want to delve into specifics after understanding the basics, follow the link to Consortium W3, which is responsible for officially defining and regulating the:
https://www.w3.org/Protocols/
Format
An HTTP request is in principle a mere text stream, characteristic for this format (each row of the table is a line of text, broken by CR + LF:
| REQUISIÇÃO | RESPOSTA
------------+---------------------------------+--------------------------
CABEÇALHO | METODO CAMINHO PROTOCOLO/VERSAO | PROTOCOLO/VERSAO STATUS
| Cabeçalho 1: valor1 | Cabeçalho 1: valor1
| Cabeçalho 2: valor2 ... | Cabeçalho 2: valor2 ...
| Cabeçalho N: valorN | Cabeçalho N: valorN
linha vazia | |
CORPO | DADOS DO PEDIDO | DADOS DA RESPOSTA
The MÉTODO
is the GET
, POST
, PUT
, DELETE
, but it is not limited to these. Even, you can extend the protocol and define specific methods for the application you are using (and need to do the corresponding method on the server side).
What are the HTTP request methods, and what is the difference between them?
What are the advantages of using the right HTTP methods?
When to use GET function and when to use POST function?
the CAMINHO
is the one that comes after the URL. Just be a slash /
or is a path to resource such as /blog/47894/como-fazer-amigos-e-influenciar-pessoas
. May include a query string, as ?mode=json
at the end.
Note that anchors are not part of the path. At an address like /index.html?order=date#details
, the way is just /index.html?order=date
.
the PROTOCOLO/VERSAO
tend to be HTTP/1.1
, very rarely HTTP/1.0
, and now several websites mainstream work with the HTTP/2
.
About that, there are some details here:
What are the differences between HTTP 1.1 vs HTTP 1.0?
Exemplifying
When you access in the browser a site like www.exemplo.com.br
, your browser solves the address (transforms www.exemplo.com.br
at an IP address, using DNS).
It then connects via TCP to the IP obtained, in principle at port 80 (which is the HTTP standard, with 443 being the HTTPS standard). Once connected, it will send something like this, verbatim:
GET / HTTP/1.1
Host: www.exemplo.com.br
and that’s it. Assuming there’s a page in the requested address, you’ll get something like this back:
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Encoding: UTF-8
Content-Length: 351
Connection: close
<html>...
Note that it’s almost the same thing, only in the answer instead of you having METODO CAMINHO PROTOCOLO
you have PROTOCOLO STATUS DESCRICAO_DO_STATUS
in the first line.
Methods
Once we understand the basic part of the protocol, let’s see what changes instead of a GET
have a POST
. In the case of POST
we have some extra information to send, and as described above, we use a blank line to separate the contents from the header:
POST /formulariodeinscricao.html HTTP/1.1
Host: www.example.com
nome=gato&senha=secret
Note that the keyword here is the POST
, the information of the first line, and in the body of the request (after the blank line) we have the values sent. In case I used the most common format of Web forms, the format may vary depending on the case.
If it was a file upload with PUT
might as well be so:
PUT /upload.html HTTP/1.1
Host: www.example.com
DADOS_DO_ARQUIVO..........
Test tool
There are some online tools that help a lot to investigate and "debug" HTTP requests, one of them is this API, with several endpoints, which show a diversity of information, which helps a lot to test separately the sending and receiving part of your application:
https://httpbin.org/
More references
What is a "stateless protocol", like HTTP?
https://pt.wikipedia.org/wiki/Hypertext_Transfer_Protocol
Just in advance: the HTTP protocol does not process anything. It only regulates how the data should be communicated. Who processes HTTP is the application.
– Bacco
A.pt OS response involving the HTTP protocol: http://answall.com/a/66765/8493 also has 2 links to the subject.
– KaduAmaral
Related: What is a "stateless protocol", like HTTP?
– Jéf Bueno