WordPress\AiClient\Providers\Http\DTO

Request::getBody │ public │ WP 0.1.0

Gets the request body.

For GET requests, returns null. For POST/PUT/PATCH requests:

  • If body is set, returns it as-is
  • If data is set and Content-Type is JSON, returns JSON-encoded data
  • If data is set and Content-Type is form, returns URL-encoded data

Метод класса: Request{}

Хуков нет.

Возвращает

string|null. The body.

Использование

$Request = new Request();
$Request->getBody(): ?string;

Список изменений

С версии 0.1.0 Введена.

Код Request::getBody() WP 7.1.4

public function getBody(): ?string
{
    // GET requests don't have a body
    if (!$this->method->hasBody()) {
        return null;
    }
    // If body is set, return it as-is
    if ($this->body !== null) {
        return $this->body;
    }
    // If data is set, encode based on content type
    if ($this->data !== null) {
        $contentType = $this->getContentType();
        // JSON encoding
        if ($contentType !== null && stripos($contentType, 'application/json') !== \false) {
            return json_encode($this->data, \JSON_THROW_ON_ERROR);
        }
        // Default to URL encoding for forms
        return http_build_query($this->data);
    }
    return null;
}