Junior — Middle
Explain what the main components of an HTTP request look like and what information they contain.
sobes.tech AI
Answer from AI
An HTTP request consists of several main components:
-
Request Line — contains the request method (GET, POST, etc.), URL, and HTTP protocol version. Example:
GET /index.html HTTP/1.1 -
Headers — key-value pairs that convey additional information about the request, such as:
Host: the domain name of the serverUser-Agent: information about the clientAccept: data types the client is willing to accept
-
Blank line — separates headers from the body of the request.
-
Body — contains data sent by the client to the server (e.g., form data in a POST request). In GET requests, the body is usually absent.
In PHP, access to these components can be obtained through superglobal arrays, such as $_SERVER for headers and method, and php://input for the request body.