Sobes.tech
Intern

What is contained in the request body?

sobes.tech AI

Answer from AI

The body of an HTTP request contains data sent by the client to the server.

Depending on the HTTP method and request type, the body may contain:

  • Form parameters: when submitting data from a web form (using POST, PUT methods).
  • JSON or XML data: for exchanging structured data between client and server, common in RESTful APIs.
  • Binary data: for example, when uploading files.
  • Other data types depending on the Content-Type header.

Examples:

// POST request body with JSON data
{
  "name": "Anna",
  "age": 30
}
// PUT request body with XML data
<user>
  <name>Peter</name>
  <age>25</age>
</user>
<!-- POST request body with form data (application/x-www-form-urlencoded) -->
<form>
  <input type="text" name="username" value="user123" />
  <input type="password" name="password" value="secret" />
</form>

The body is absent in requests with methods that do not imply sending data in the body, such as GET or HEAD.

The content of the body is determined by the request headers, particularly Content-Type, which indicates the data format.