Academic Block

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

Code
Category
Meaning
200
Success
OK – Request succeeded
201
Success
Created – Resource was created
301
Redirection
Moved Permanently
400
Client Error
Bad Request
401
Client Error
Unauthorized
403
Client Error
Forbidden
404
Client Error
Not Found
500
Server Error
Internal Server Error
503
Server Error
Service Unavailable

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

+ What are 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).

+ What is the structure of an HTTP request? >

An HTTP request contains a start line (method, URL, HTTP version), followed by headers, a blank line, and an optional body.

+ What is the structure of an HTTP response? >

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.

+ What do the different status code ranges mean? >

1xx = Informational, 2xx = Success, 3xx = Redirection, 4xx = Client Error, 5xx = Server Error.

+ Why is the 404 status code so common? >

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.

📝 HTML Code
👁️ Preview (Rendered HTML)

Click “Run Code” to see the result here.