phasync
Request / __construct

Method

Request::__construct

Creates a request.

Description#

public Request::__construct(
    string $method,
    string $requestTarget,
    ?StreamInterface $body = null,
    array $headers = [],
    string $protocolVersion = '1.1'
)

Parameters#

$method string
Case-sensitive HTTP method
$requestTarget string
Request target, e.g. "/path?query=value"; '' becomes "/"
$body ?StreamInterface = null
Body; null is an empty stream
$headers array = []
Array of header names => values
$protocolVersion string = '1.1'
The HTTP protocol version, typically "1.1" or "1.0"

Errors / Exceptions#

ExceptionWhen
InvalidArgumentExceptionFor a method that is not an RFC 7230 token, a request target containing whitespace or control characters, or an invalid header (a value that is not a string is rejected)