Protocol HTTP: GET, POST, cookies i cistella de la compra

Informática y Telecomunicaciones4,78 KB

Albert Pons <[email protected]>

23:52 (fa 6 minuts)
para mí

L'usuari demana al servidor prova.com el document que es troba a /productes/test/info.html.

Petició del client al servidor (XXX significa la informació pertinent):

GET /productes/test/info.html HTTP/1.1
START LINE
Date: XXX
Connection: close
GENERAL HEADER
Host: XXX

Resposta del servidor al client:

HTTP/1.1 200 OK
START LINE
Date: XXX
Connection: close
GENERAL HEADER
Server: XXX
RESPONSE HEADER
Content-Type: text/html
Content-Length: XXX
ENTITY HEADER

EMPTY LINE
<!DOCTYPE html>
XXX
</html>

L'usuari envia el formulari

Petició del client al servidor:

GET /productes/test/upload_info.php?name=Joan&age=21&updates=yes HTTP/1.1
START LINE
Date: XXX
Connection: close
GENERAL HEADER
Host: www.prova.com
Accept: text/html
User-Agent: XXX
REQUEST HEADER

EMPTY LINE

Resposta del servidor al client:

HTTP/1.1 200 OK
START LINE
Date: XXX
Connection: close
GENERAL HEADER
Server: XXX
RESPONSE HEADER
Content-Type: text/html
Content-Length: XXX
ENTITY HEADER

EMPTY LINE
<!DOCTYPE html>
XXX
</html>
MESSAGE BODY

L'usuari amb POST en lloc de GET

Petició del client al servidor:

POST /productes/test/upload_info.php HTTP/1.1
START LINE
Date: XXX
Connection: close
GENERAL HEADER
Host: www.prova.com
Accept: text/html
User-Agent: XXX
REQUEST HEADER
Content-Type: application/x-www-form-urlencoded
Content-Length: XXX
ENTITY HEADER

EMPTY LINE
name=Joan&age=21&updates=yes
MESSAGE BODY

Resposta del servidor al client:

HTTP/1.1 200 OK
START LINE
Date: XXX
Connection: close
GENERAL HEADER
Server: XXX
RESPONSE HEADER
Content-Type: text/html
Content-Length: XXX
ENTITY HEADER

EMPTY LINE
<!DOCTYPE html>
XXX
</html>

Petició del client, cistella de la compra: necessitem cookies

Client al servidor, petició:

GET /productes/vins/comprarRioja.html HTTP/1.1
Date: XXX
Connection: close
Host: www.botiga.com
Accept: text/html
User-Agent: XXX

Resposta del servidor:

HTTP/1.1 200 OK
Date: XXX
Connection: close
Server: XXX
Set-Cookie: cistella=rioja
Content-Type: text/html
Content-Length: XXX

Si el client vol tornar a comprar un altre producte, es torna la cookie:

GET /productes/vins/comprarPenedes.html HTTP/1.1
Date: XXX
Connection: close
Host: www.botiga.com
Cookie: cistella=rioja
Accept: text/html
User-Agent: XXX

Resposta del servidor:

HTTP/1.1 200 OK
Date: XXX
Connection: close
Server: XXX
Cookie: cistella=rioja,penedes
Content-Type: text/html
Content-Length: XXX

+ el document

Si ho volguéssim fer amb sessions, la cookie portaria un identificador de sessió que feria referència a una entrada de la base de dades.

Descargar

PDF Word HTML