Can anyone explain how the communication takes place between the browser and web server? I want to learn how
- GET, POST verbs (among others)
- cookies
- sessions
- query strings
work behind the scene.
Can anyone explain how the communication takes place between the browser and web server? I want to learn how
work behind the scene.
The links for specifications of each aspect of the question is as follows:
GET, POST verbs (among others) - The HTTP Specification exhaustively discusses all aspects of HTTP communication (the protocol for communication between the web server and the browser). It explains the Request message and Response message protocols.
Cookies - are set by attaching a
Set-Cookie
HTTP Header to the HTTP response.QueryStrings - are the part of the URL in the HTTP request that follow the first occurrence of a "?" character. The linked specification is for section 3.4 of the URI specification.
Sessions - HTTP is a synchronous, stateless protocol. Sessions, or the illusion of state, can be created by (1) using cookies to store state data as plain text on the client's computer, (2) passing data-values in the URL and querystring of the request, (3) submitting POST requests with a collection of values that may indicate state and, (4) storing state information by a server-side persistence mechanism that is retrieved by a session-key (the session key is resolved from either the cookie, URL/Querystring or POST value collection.
An explanation of HTTP can go on for days, but I have attempted to provide a concise yet conceptually complete answer, and include the appropriate links for further reading of official specifications.
Your browser first resolves the servername via DNS to an IP. Then it opens a TCP connection to the webserver and tries to communicate via HTTP. Usually that is on TCP-port 80 but you can specify a different one (
http://server:portnumber
).HTTP looks like this:
Once it is connected, it sends the request, which looks like:
E.g., a header might be
Authorization
orRange
. See here for more.Then the server responds like this:
E.g., a header might be
Date
orContent-Type
. See here for more.Look at Wikipedia for HTTP for some more information about this protocol.