Course contents

Unit 7: TCP, UDP and PortsLesson 7.3.1 (16 of 23 in this unit)65 of 104 in the Network Fundamentals course

HTTP: how the web talks

Why can a website answer with 404 even when your network connection is working? Follow a request from the browser to the application, then use the reply to locate the problem.

Beginner · 7 min read

Covers Requests & responses, Methods and Status codes.

Technical definition

HTTP (Hypertext Transfer Protocol) is the application-layer request-response protocol that web clients use to ask servers for pages, images and other resources. Unencrypted HTTP runs over TCP, by default on port 80.

What happens after you press Enter

You type example.com into your browser and press Enter. Less than a second later, a page appears. Behind that page, your browser and a web server had a short, polite conversation. The rules for that conversation are called HTTP.

Request first, response second

HTTP (Hypertext Transfer Protocol) is the protocol browsers use to ask web servers for pages, images and data. It works by request and response: the client (your browser) initiates a request, and the server answers. Plain HTTP uses TCP port 80. TCP delivers an ordered byte stream while the connection works; a broken connection can still end in an error. A TCP acknowledgement does not prove the application processed the request.

For this first-visit HTTP/1.1 example, assume there is no cached address or existing connection. DNS (Domain Name System) resolves the name, then TCP opens a connection to port 80. A cached DNS answer or reusable connection can skip those setup steps. HTTP/3 instead uses QUIC over UDP; the request and response meanings remain familiar.

Diagram
Loading a web page, step by step
Loading a web page, step by step
Your laptopIP 192.168.1.20Home routerInternetDNS serverWeb serverIP 203.0.113.10

Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • Your laptop: IP 192.168.1.20
  • Web server: IP 203.0.113.10
  1. 1. 1. DNS lookup. The laptop asks: what is the IP address of example.com? The answer is 203.0.113.10.
  2. 2. 2. TCP handshake. SYN, SYN-ACK and ACK to port 80 open a reliable connection.
  3. 3. 3. HTTP request. The browser asks for the page with a GET request.
  4. 4. 4. HTTP response. The server sends back a status code, some headers and the page itself.
Figure 1. An uncached HTTP/1.1 first visit: resolve the name, connect, request, reply.

The request and the response

HTTP/1.1 uses text for its start line and headers; the body can contain binary data, such as an image. HTTP/2 and HTTP/3 represent message information using binary frames. The request names a method (what to do) and a path (which resource). The response starts with a status code, a three-digit number that shows the result. Both carry headers: extra lines of information such as the type of content or its size.

Step 1 of 4 · GET /index.html
Browser
192.168.1.20:51544
Internet
Web server
203.0.113.10:80

Device key: Browser (laptop)

Arrows run from each message's sender to its receiver. Rows show message order, not separate cables or elapsed time to scale. Port numbers identify services or conversations, not physical switch sockets.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • Browser: 192.168.1.20:51544
  • Web server: 203.0.113.10:80

HTTP/1.1 normally permits connection reuse. These are logical application messages; packets may be split or combined, and connections can be closed.

Methods: what the browser asks for

Diagram
Methods: what the browser asks for
Methods: what the browser asks for
MethodWhat it asks the server to doEveryday example
GETSend me this resourceOpening a page
POSTTake this data and process itSending a login or contact form
PUTStore this data at this pathUploading or replacing a file through an API
DELETERemove this resourceDeleting an item through an API
HEADSend only the headers, not the bodyChecking if a page exists
Read each row across: the left box names the item, the others describe it.

Status codes: how the server answers

The first digit tells you the kind of answer:

Diagram
Status codes: how the server answers
Status codes: how the server answers
ClassMeaningCommon codes
2xxSuccess200 OK
3xxRedirection or cache-related handling, depending on the code301 Moved Permanently, 302 Found
4xxA problem with the request (client error)401 Unauthorized, 403 Forbidden, 404 Not Found
5xxThe server failed to handle a valid request500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable
Read each row across: the left box names the item, the others describe it.

An HTTP status proves that an HTTP-speaking endpoint replied, not that every part of the path is healthy. A reverse proxy (a service in front of the application) can return 502 while its connection to the application server is broken. A cached address can also mean no new DNS lookup occurred. Locate the responding endpoint before declaring DNS, routing or the origin server healthy.

Diagram
A reply can come from the proxy
A reply can come from the proxy
A reply can come from the proxyLogical application path: the browser connects to a reverse proxy at 203.0.113.10 port 80. The proxy cannot connect to its application server at 10.20.0.10 port 8080 and returns HTTP 502 to the browser. Receiving that response does not prove backend reachability.1. Browser2. Reverse proxy3. ApplicationClient source port51544 (example)203.0.113.10:8010.20.0.10:8080HTTP requestConnection failsReceives 502Generates 502Not reachedThe browser-to-proxy path works; the backend path does not.

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Figure 2. The proxy answers while the application path fails. A received HTTP status identifies a responder, not a healthy end-to-end service.

In Figure 2, the browser reaches the front-end service on port 80. The proxy then tries a separate connection to application port 8080. That connection fails, so the proxy generates 502 Bad Gateway. Check the proxy log and its backend route, firewall and application listener; repeating the browser DNS lookup will not repair that backend fault. Ports here identify application services, not switch interfaces.

Stateless and unencrypted by design

HTTP is stateless: the protocol does not require a request to belong to a remembered conversation. Applications can still store login sessions, carts and other state in databases or memory. A browser can carry a session identifier in a cookie with each request to that site.

Plain HTTP provides no transport encryption. An observer with access to the traffic can read or alter it. HTTPS adds protection; POST alone does not encrypt a password. A redirect only takes effect after the initial HTTP request has already crossed the network. Browsers may also upgrade directly to HTTPS through site security policies.

Learn more: HTTPS and TLS

Read the headers, then test the application

On macOS, Linux or Windows (type curl.exe in PowerShell), curl can show the response headers. The Windows command below forces HTTP/1.1 for comparison with the figure and limits the operation to 15 seconds. Use curl instead of curl.exe on Linux/macOS. The -I option sends HEAD, so no response body is transferred. A service can handle HEAD differently from GET.

curl.exe --http1.1 -I --max-time 15 http://example.com

Ask only for the headers of the page.

Example output
HTTP/1.1 301 Moved Permanently
Location: https://example.com/
Content-Type: text/html
Content-Length: 162

This is a constructed redirect example, not a claim about the current response from example.com. What to look for: the first line is the status line. The 301 Moved Permanently code and the Location header show that the server is redirecting you to the HTTPS address. Content-Type and Content-Length describe the (short) body the server would send. You can also try the HTTP Headers tool to see the headers of any public site.

Try it: separate connection failure from an HTTP error

Use the public example.com demonstration site or an authorised lab server. Start with HEAD, then use the command below to make a GET request and display its response headers. -D - writes headers to the screen, -o NUL discards the body on Windows, and --max-time 15 prevents an indefinite wait. On Linux/macOS use -o /dev/null. These commands make requests but do not change your computer's network settings.

curl.exe --http1.1 -D - -o NUL --max-time 15 http://example.com

Send GET and inspect the response headers without displaying the body.

Record the status and any Location header. curl does not follow a redirect by default. If DNS cannot resolve the name, there is no HTTP reply in this direct example. If the connection is refused, investigate the listener or a rejecting firewall. If a 404 arrives, check the hostname and resource path. Repeat after correcting the fault and compare the evidence. In a proxy-based network, the proxy may resolve names or generate its own reply.

Test yourself on HTTP

Predict · scenario 1

You click a link on a website and the browser shows "404 Not Found". What does this tell you?

Predict · scenario 2

You fill in a login form and click Sign in. Which method does the browser normally use to send the form?

Predict · scenario 3

In a direct first visit with no cached address, no existing connection and no proxy, DNS resolution fails. Can the browser start HTTP to that named server?

Technical references

RFC 9110: HTTP semantics; RFC 9114: HTTP/3; curl command reference.