The internet is an essential part of our lives, and many of us use it every day.
But have you ever wondered how the websites we visit load on our devices?
It’s all made possible by a protocol called HTTP.
What Is HTTP?
HTTP stands for Hypertext Transfer Protocol. It’s a set of rules that governs how information is exchanged between a client (such as your web browser) and a server (where the website’s content is stored).
HTTP is the foundation of any data exchange on the web.
Stay One Step Ahead of Cyber Threats
What Is in an HTTP Request?
An HTTP request is a message sent by the client to the server, asking for specific data or to perform an action.
An HTTP request contains several elements:
- Request Line, which includes:
- HTTP Method
- HTTP Version
- Headers, which include the following:
- Authorization (if needed)
- Request Body (optional)
Example of an HTTP Request
GET /example-page.html HTTP/1.1 Host: www.example.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.3 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8 Accept-Language: en-US,en;q=0.5 Connection: keep-alive
In this example, the client is requesting the resource “/example-page.html” from the server “www.example.com” using the HTTP/1.1 protocol.
The client provides additional information in the headers, such as its browser and operating system (User-Agent), the types of content it can accept (Accept), and its language preference (Accept-Language).
The Connection header indicates that the client prefers to keep the connection alive for multiple requests if possible.
Since this is a GET request, there is no request body.
What Is an HTTP Method?
An HTTP method indicates the desired action to be performed on the requested resource.
The most common HTTP methods are:
- GET: Requests data from a specified resource.
- POST: Submits data to be processed to a specified resource.
- PUT: Updates an existing resource with new data.
- DELETE: Deletes a specified resource.
What Are HTTP Request Headers?
HTTP request headers provide additional information about the request, such as the type of browser being used or the type of data the client can accept.
Example of Request Headers
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3
What Is in an HTTP Request Body?
The request body contains data sent by the client to the server, typically in POST or PUT requests.
This data could be form data, JSON, or other formats, depending on the content type specified in the request headers.
What Is in an HTTP Response?
An HTTP response is the server’s message back to the client containing the result of the request.
An HTTP response consists of the following:
- Status Line: Indicates the HTTP version, status code, and status message.
- Headers: Provide additional information about the response.
- Response Body: Contains the requested data or the result of the requested action.
Example of an HTTP Response
HTTP/1.1 200 OK Date: Mon, 18 Apr 2023 12:00:00 GMT Server: Apache/2.4.48 (Unix) Content-Type: text/html; charset=UTF-8 Content-Length: 512 Connection: keep-alive <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example Page</title> </head> <body> <h1>Welcome to the Example Page!</h1> <p>This is a simple example of an HTTP response.</p> </body> </html>
What Is an HTTP Status Code?
An HTTP status code is a three-digit number that indicates the outcome of an HTTP request.
Some common status codes are:
- 200 OK: The request was successful.
- 404 Not Found: The requested resource could not be found on the server.
- 500 Internal Server Error: The server encountered an error while processing the request.
What Are HTTP Response Headers?
HTTP response headers provide additional information about the response, such as the type and length of the content being sent.
Example of Response Headers
Content-Type: text/html; charset=UTF-8 Content-Length: 138
What Is in an HTTP Response Body?
The response body contains the data requested by the client or the result of the requested action.
This could be an HTML page, an image, a JSON object, or other types of data.
"Amateurs hack systems, professionals hack people."
-- Bruce Schneier, a renown computer security professional