Skip to content

HTTP Basics


HTTP Overview

  • HTTP is a simple, stateless protocol.
  • A browser makes a request.
  • The server answers.
  • The transaction is done. That’s it!

The HTTP Request

  • The browser makes a socket connection.
  • The browser sends an HTTP command.
    • GET /index.html HTTP/1.1
  • The browser sends a list of headers.
  • Examples:
GET / HTTP/1.1
Host: localhost:4444
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
GET / HTTP/1.1
Host: 172.16.82.168:4444
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0.3 Safari/604.5.6
Accept-Language: en-us
DNT: 1
Accept-Encoding: gzip, deflate
GET / HTTP/1.1
Host: localhost:4444
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

The HTTP Response

  • The server processes the request and creates a response
  • The server sends a status line
HTTP/1.1 200 OK
  • The server sends a list of response headers.
Host: localhost:4444
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0

Demo: Using telnet to access a web site.

HTTP Headers in Developer Tools

You can use the developer tools in modern browsers to see the HTTP headers. Here are the steps for Chrome.

Open the developer tools. The quickest way is to press Control-Shift-I.

Then follow these steps.

  1. Enter the URL of a site
  2. Click on the Network tab.
  3. Click on the site's resource listed in the list on the left.
  4. Click on the Headers tab.