Skip to content
Lesson: HTTP Requests and ResponsesSwitch
← Security Operations

Security investigations

HTTP Requests and Responses

See what a browser and a web server actually send each other.

HTTP is the protocol of the web. A client sends a request and a server sends back a response. To protect a web application, you first need to read both.

The request

A request starts with a method, a path and a version, followed by headers and sometimes a body:

text
GET /products?id=7 HTTP/1.1
Host: shop.example.com
User-Agent: curl/8.5.0
Accept: */*

Common methods are GET to fetch, POST to submit data, PUT to replace and DELETE to remove. GET is defined as safe: it should not be used to change things.

The response

The response has a status line, headers and usually a body:

text
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 512

<!doctype html>...

The first digit of the status code gives the class: 2xx success, 3xx redirection, 4xx client error, 5xx server error. 401 means authentication is missing or failed, 403 means the server refuses the request, and 404 means not found.

See it yourself

curl -v shows what is sent (>) and received (<):

bash
$ curl -v http://example.com/ -o /dev/null
> GET / HTTP/1.1
> Host: example.com
< HTTP/1.1 200 OK
< Content-Type: text/html

The real output has more lines. curl -I asks for headers only, using the HEAD method.

HTTP/2 and HTTP/3 carry the same ideas of methods, headers and status codes in a binary form, so tools may show a different version number.

Never trust the request

Everything in a request is under the sender's control: the path, query, headers, cookies and body. Someone can send values your form would never produce. The server must validate input itself. Checks in the browser are a convenience for honest users, not a protection.

Also avoid putting secrets in the URL. Addresses are commonly recorded in server logs and browser history.

Try it

Run curl -v against a server you own, or against http://example.com/. Identify the method, the Host header, the status code and the content type. Then request a path that does not exist and compare. The networking and SSH lab gives you a shell to practise in.

Check your understanding

HTTP Requests and Responses

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.