Fundamentals 12 min read

Mastering HTTP: Methods, Headers, URLs, and Status Codes Explained

This comprehensive guide explains the HTTP protocol, covering its connection model, request and response message structures, common methods, URL components, version differences, header field categories, the request/response lifecycle, status code classifications, and the practical distinctions between GET and POST.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Mastering HTTP: Methods, Headers, URLs, and Status Codes Explained

HTTP Overview

HTTP (Hypertext Transfer Protocol) uses TCP as its transport layer; the protocol itself is stateless. It follows a request/response model where clients send requests and servers return responses.

Request Message

CRLF denotes carriage return and line feed.

Examples of GET and POST request messages are illustrated with images.

HTTP Methods

OPTIONS : Server returns supported methods for a resource.

HEAD : Like GET but without a response body, useful for metadata.

GET : Retrieves data without side effects; should not modify server state.

POST : Submits data to be processed, potentially creating or updating resources.

PUT : Uploads a new version of a resource.

DELETE : Removes the specified resource.

TRACE : Echoes the received request for testing.

CONNECT : Used by proxies to establish a tunnel, often for SSL.

In practice, GET and POST are the most frequently used methods.

URL Structure

A typical URL consists of <scheme>://<host>:<port>/<path>. Common schemes include http, https, ftp, mailto, ldap, file, news, gopher, telnet.

Host: domain name on the Internet.

Port: optional, defaults to protocol standard.

Path: absolute (full path) or relative (relative to current location).

HTTP Versions

HTTP/1.0 uses non‑persistent connections (new TCP handshake per request). HTTP/1.1 introduces persistent connections (keep‑alive) and pipelining, reducing latency by allowing multiple requests over a single connection.

Header Field Categories

Four types of header fields exist:

General : Used by both request and response messages.

Request : Sent by the client to the server.

Response : Sent by the server to the client.

Entity : Describe the body of the message.

Examples of common header fields (general, request, response, entity) are listed in the original source.

HTTP Transaction Process

The typical flow for a browser request using HTTP/1.0:

Parse the URL.

Resolve the domain name via DNS.

Obtain the IP address.

Establish a TCP connection to the server (IP + port).

Send the request line (e.g., GET /question/1742817.html HTTP/1.0).

Server responds with the requested resource.

Close the TCP connection.

Browser renders the HTML content.

Status Codes

Classes of status codes:

1xx – Informational.

2xx – Success (e.g., 200 OK).

3xx – Redirection.

4xx – Client error (e.g., 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found).

5xx – Server error (e.g., 500 Internal Server Error, 503 Service Unavailable).

GET vs POST

GET appends data to the URL, visible in the address bar, and is limited by URL length constraints. POST sends data in the request body, not shown in the URL, and generally allows larger payloads, though server configurations may impose limits. POST is considered more secure for transmitting sensitive data because it does not expose parameters in the URL.

Author: Wei Erxiao Source: http://blog.csdn.net/qq_35116353/article/details/77203521
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

HTTPStatus Codesweb protocolHeadersrequest methods
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.