This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 2: HTTP

HTTP request

face Josiah Wang

What does an HTTP request look like?

It could look like this:

GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/12.0

The first line is a request line.

Here, "GET" is the request method, which tells the server that the client wants to retrieve something. That something is the second item "/index.html" (the resource). This essentially tells the server to retrieve the file "/index.html" (the resource) from the server.

The subsequent lines form the request header. "Host" is a compulsory header to point to the server. Most of the other possible request header fields are less relevant. I am showing you "User-Agent" in the example simply to demonstrate how the server knows what browser you are using.

There can also be an optional message body, which can be used with other request methods like "POST" and "PUT" (we will discuss these request methods later).