Article
HTTP, how browsers ask for pages
You click a link, and a page appears. In between, your browser and a web server had a short conversation. It follows strict rules, so every browser and every server can understand each other. Those rules are a protocol called HTTP.
Ask and answer
HTTP stands for HyperText Transfer Protocol. It describes how a browser asks for web pages and how a server answers. The browser is the client, the one who asks. Every exchange has two parts: a request and a response.
A request has a method and a path. The most common method is GET, which means "please send me this page". Here is a small request:
GET /lessons/fractions.html HTTP/1.1
Host: www.example.comThe server replies with a response. Its first line holds a status code, a number that says how it went:
HTTP/1.1 200 OK
Content-Type: text/html
(the text of the page comes next)Some status codes you should recognise:
| Code | Meaning |
|---|---|
| 200 | OK: here is what you asked for |
| 301 | The page has moved to a new address |
| 404 | Not found: the server has no page at that path |
| 500 | Server error: something went wrong on the server |
The other method you will see is POST. A browser uses it to send information to a server, for example when you submit a form.
Check your understanding
A browser receives a response with the status code 404. What does this mean?
One page, many requests
A web page is often made of many files: the HTML text, a style file, and several images. The browser asks for the HTML first. It reads it and finds the other files it needs. Then it sends a separate request for each one.
Here is the browser loading one page that contains a style file and a picture:
One page, three requests
- 1
Browser → Web server
GET the page
- 2
Web server → Browser
200 OK and the page text
- The browser reads the page and finds a style file and a picture to fetch.
- 3
Browser → Web server
GET the style file
- 4
Web server → Browser
200 OK and the style file
- 5
Browser → Web server
GET the picture
- 6
Web server → Browser
200 OK and the picture
Each request and each response travels as packets across the Internet. HTTP does not move the packets itself. It uses the lower-level protocols you already know: TCP and IP. HTTP sets the meaning of the messages. TCP and IP do the delivery.
Check your understanding
Which statement about HTTP and the packets that carry it is correct?
Worked example
Rosa types https://www.example.com/lessons/fractions.html and presses Enter. All the protocols in this lesson work together:
| Step | What happens | Protocol |
|---|---|---|
| 1 | The browser asks for the IP address of www.example.com | DNS |
| 2 | The browser opens a reliable connection to that address | TCP and IP |
| 3 | It sends GET /lessons/fractions.html | HTTP |
| 4 | The server replies with status 200 and the page text | HTTP |
| 5 | The browser finds an image in the page and sends another GET | HTTP |
| 6 | The browser shows the finished page | (the browser itself) |
If she later clicks a broken link, step 4 would return 404 instead of 200. Her connection is fine. The server is working. It simply has no page at that path.
Common mistakes
- "A 404 means the Internet is down." No. A 404 response proves the server answered. It just did not have that page.
- "HTTP finds the IP address." That is DNS. HTTP asks for the page after the address is known.
- "One request brings the whole page." Each file needs its own request.
- "HTTP sends the packets." HTTP defines the messages. TCP and IP carry them.
On the exam
Remember the pairing: DNS finds the address, HTTP asks for the page, and TCP and IP deliver the packets. Questions often ask you to put these in order, or to say which protocol a problem belongs to.
Key words
HTTP: the protocol browsers and web servers use to request and send web pages.
Client: the program or device that asks, such as a browser.
Request: a message from a client asking for something.
Response: the message a server sends back.
Status code: a number in a response that says whether the request worked.