0.1.HTTP
βοΈ What Is HTTP?
HTTP stands for HyperText Transfer Protocol.\ It is a TCP-based protocol used for transferring data between websites and applications.
-
The default protocol for web pages.
-
It typically runs on Port 80 (though this can be changed in the server settings).
-
Itβs used for communication between Web Applications and Mobile Applications.
The communication happens between a Client (the user or browser) and a Server,\ through Requests and Responses.
π What Is a URL and What Does It Contain?
URL stands for Uniform Resource Locator β\ itβs the address or link used to access a specific web page.
Example π
Scheme Host Directory Parameters
| | | |
| | | |
http://image.google.com:80/Secrets/index.php?id=13&message=Hello#top
| | | |
Second-Level Domain Port File Fragment
| Part | Description |
|---|---|
| Scheme | The protocol type (e.g., http or https). |
| Host | The websiteβs domain name or address. |
| Port | The port used for the connection (default: 80 or 443). |
| Directory / File Path | The internal path on the server to access a page or file. |
| Parameters | Data values sent to the server (e.g., ?id=13). |
| Fragment | A specific section on a page, indicated by #. |
π HTTP vs HTTPS
In HTTP, all data is transmitted in plain text,\ which means it can be intercepted or read β for example, through a Man-in-the-Middle (MITM) attack.
This issue was solved with HTTPS,\ the secure version of HTTP that adds encryption via SSL/TLS.
| Protocol | Default Port | Security |
|---|---|---|
| HTTP | 80 | β Unencrypted |
| HTTPS | 443 | β Encrypted and secure |
π Main Difference: The presence (or absence) of encryption:
π© Components of an HTTP Request
An HTTP Request is what the client sends to the server.\ It consists of the following parts:
-
Method β The type of operation (e.g., GET, POST, etc.)
-
Path β The requested path on the server
-
HTTP Version β The version of the HTTP protocol
-
Headers β Additional information such as content type or browser details
-
Body β Contains the data (used in methods like POST)
π§Ύ Example of an HTTP Request:
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept-Language: en-US
Connection: keep-alive
π€ Components of an HTTP Response
An HTTP Response is what the server sends back to the client.\ It contains:
-
Status Line β Includes the status code and message (e.g.,
200 OK) -
Headers β Provide details about the server or file
-
Body β Contains the actual data or webpage content
π§Ύ Example of an HTTP Response:
HTTP/1.1 200 OK
Date: Sun, 12 Oct 2025 20:00:00 GMT
Server: Apache/2.4.52
Content-Type: text/html
Content-Length: 1024
<html>
<body>
<h1>Welcome to Example Website</h1>
</body>
</html>
π§± Types of HTTP Headers
π© Request Headers
| Header Name | Description |
|---|---|
| Host | Contains the IP or domain of the target server. |
| User-Agent | Contains information about the client device or browser. |
| Connection | Specifies whether to keep the connection alive after the request. |
| Referer | The page from which the request originated. |
| Accept-Language | The languages supported by the client. |
| Accept-Encoding | Supported encoding/compression types. |
| Accept | The data types the client accepts from the server. |
| Cookie | Contains session or authentication data. |
| Content-Length | The size of the request body data. |
| Content-Type | The format of the request body (e.g., application/json). |
π€ Response Headers
| Header Name | Description |
|---|---|
| Date | The date and time the response was sent. |
| Location | Used for redirects. |
| Set-Cookie | Used to create or update cookies. |
| Server | Contains information about the web server. |
π§ HTTP Methods
| Method | Description |
|---|---|
| GET | Retrieves data from the server β no body (data in URL). |
| POST | Sends data to the server (e.g., forms or files) via the body. |
| HEAD | Similar to GET but without a body, used for validation. |
| OPTIONS | Lists the allowed HTTP methods on the server. |
| PUT | Creates or replaces existing data. |
| PATCH | Updates part of an existing resource. |
| DELETE | Deletes data from the server. |
πΈ Common usage:
GET and POST β Used in web applications.
PUT, PATCH, and DELETE β Common in APIs.
π HTTP Response Codes
| Category | Meaning |
|---|---|
| 1xx | Informational or processing status. |
| 2xx | Success responses. |
| 3xx | Redirection responses. |
| 4xx | Client-side errors. |
| 5xx | Server-side errors. |
Most Common Status Codes:
| Code | Meaning |
|---|---|
| 200 OK | Request succeeded. |
| 302 Found | Resource found (redirect). |
| 400 Bad Request | Invalid request syntax. |
| 403 Forbidden | Access denied β no permission. |
| 404 Not Found | Resource not found. |
| 500 Internal Server Error | Server encountered an internal issue. |