Sobes.tech
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:

  1. Request Line — contains the request method (GET, POST, etc.), URL, and HTTP protocol version. Example: GET /index.html HTTP/1.1

  2. Headers — key-value pairs that convey additional information about the request, such as:

    • Host: the domain name of the server
    • User-Agent: information about the client
    • Accept: data types the client is willing to accept
  3. Blank line — separates headers from the body of the request.

  4. 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.