How a browser sends a request to a web server
From an address to a response
A browser is an HTTP client: it asks for resources such as pages and images. A URL tells it how to identify a resource. For a normal HTTP/1.1 visit, the browser establishes or reuses a TCP connection to the destination, sends a request, and reads the response. With HTTPS, the connection also uses TLS to protect communication; other HTTP versions can use different transport details.
http is the scheme, 127.0.0.1 is the host address, 18080 is the port, /index.html is the path, view=full is the query and hours is the fragment. The fragment stays with the browser and is not sent as part of the HTTP request target. A port selects a network endpoint on a host; it is not a folder. Common default ports are 80 for HTTP and 443 for HTTPS when no explicit port is supplied.
How the browser finds the server
For a hostname such as shop.example.com, the client normally resolves the name to an IP address, often through DNS (Domain Name System), unless a cached result or local configuration supplies it. DNS is a name lookup mechanism, not a web page delivery service. The literal loopback IP in our lab URL needs no DNS lookup. The client then connects to the selected address and port. A connection failure may occur before any HTTP response exists.
Read an HTTP/1.1 exchange
GET /index.html?view=full HTTP/1.1Host: 127.0.0.1:18080GET requests the representation of the resource. The request target includes the path and query but not the fragment. The Host header identifies the intended authority. A blank line ends the headers; the example has no request body.
HTTP/1.1 200 OKContent-Type: text/html
<!doctype html><html lang="en"><title>Hours</title><h1>Open at 9</h1></html>The status code reports the outcome. The content type tells the browser how to interpret the response body; here the browser renders HTML. A real response includes appropriate message framing and may contain additional headers. The illustration omits them for readability.
What if something goes wrong?
A 200 indicates a successful HTTP request. A 404 indicates that the server did not find a current representation of the requested resource or will not disclose one. A 502 means a gateway or proxy received an invalid response from an upstream server; in Nginx it can also occur when an upstream connection fails. A refused connection is not a 404 because no HTTP response was received. A status code narrows the investigation but does not prove the underlying cause.
Practice: identify the address parts
For http://127.0.0.1:18080/menu.html?day=monday#lunch, identify the destination and request target. Answer: connect to 127.0.0.1 on port 18080, request /menu.html?day=monday, and keep #lunch in the browser. If menu.html is not available, a simple static server would typically return 404. Next, compare files with responses generated by an application.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
URLs and HTTP request flow
Check the main concepts taught in this lesson.
In http://127.0.0.1:18080/menu.html, what does 18080 identify?
For /menu.html?day=monday#lunch, which request target is sent in an ordinary HTTP/1.1 GET?
What does DNS normally help a browser discover for a hostname?
The connection is refused before an HTTP response arrives. What can you conclude?
Which response header tells a browser that the body is HTML?