HTTP Messages Get Certified
Understanding HTTP Messages
HTTP messages are the foundation of communication between browsers (clients) and servers. Every time you load a page, submit a form, or call an API, HTTP request and response messages are exchanged.
Two Types of HTTP Messages
- Request messages – Sent by the client to the server (asking for a resource or action).
- Response messages – Sent by the server back to the client (containing the result or an error).
Structure of an HTTP Message
- Start line – Method + URL + version (request) or version + status code (response)
- Headers – Metadata (Content-Type, Host, Authorization, etc.)
- Empty line – Separates headers from the body
- Body – Optional payload (HTML, JSON, form data, etc.)
HTTP Message Examples
1. HTTP Request Message (GET)
A simple GET request asking the server for a page.
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html
Accept-Language: en-US
2. HTTP Response Message (200 OK)
A successful response that returns HTML content.
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 127
Connection: keep-alive
<!DOCTYPE html>
<html>
<body>
<h1>Request Successful</h1>
</body>
</html>
3. HTTP POST Request (with body)
A POST request that sends form data to the server.
POST /submit-form HTTP/1.1
Host: www.example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 27
name=John&email=john@test.com
Common HTTP Status Codes
Status Code Categories
- 1xx – Informational
- 2xx – Success
- 3xx – Redirection
- 4xx – Client Error
- 5xx – Server Error
Web Resources on HTTP Messages
1. MDN : HTTP Overview
2. MDN : HTTP Request Methods
3. MDN : HTTP Response Status Codes
4. MDN : HTTP Headers
Questions and Answers related to HTTP Messages
HTTP messages are the data packets exchanged between a client (browser) and a server. There are two types: request messages (from client to server) and response messages (from server to client).
An HTTP request contains a start line (method, URL, HTTP version), followed by headers, a blank line, and an optional body.
An HTTP response starts with a status line (HTTP version, status code, reason phrase), then headers, a blank line, and an optional body containing the resource or error page.
1xx = Informational, 2xx = Success, 3xx = Redirection, 4xx = Client Error, 5xx = Server Error.
404 means the requested resource (page, image, API endpoint, etc.) could not be found on the server. It is a client error indicating a wrong or outdated URL.
🧪 Test Your HTML Code
Edit the HTML code on the left and click “Run Code” to see the result on the right.
Click “Run Code” to see the result here.