Class Request
Implements methods for HTTP requests.
Used by Cake\Network\Http\Client to contain request information for making requests.
Constants
-
stringMETHOD_DELETE ¶'DELETE'HTTP DELETE method
-
stringMETHOD_GET ¶'GET'HTTP GET method
-
stringMETHOD_HEAD ¶'HEAD'HTTP HEAD method
-
stringMETHOD_OPTIONS ¶'OPTIONS'HTTP OPTIONS method
-
stringMETHOD_PATCH ¶'PATCH'HTTP PATCH method
-
stringMETHOD_POST ¶'POST'HTTP POST method
-
stringMETHOD_PUT ¶'PUT'HTTP PUT method
-
stringMETHOD_TRACE ¶'TRACE'HTTP TRACE method
-
intSTATUS_ACCEPTED ¶202HTTP 202 code
-
intSTATUS_CREATED ¶201HTTP 201 code
-
intSTATUS_FOUND ¶302HTTP 302 code
-
intSTATUS_MOVED_PERMANENTLY ¶301HTTP 301 code
-
intSTATUS_OK ¶200HTTP 200 code
-
intSTATUS_SEE_OTHER ¶303HTTP 303 code
-
intSTATUS_TEMPORARY_REDIRECT ¶307HTTP 307 code
Property Summary
Method Summary
-
_normalizeHeader() protected
Normalize header names to Camel-Case form.
-
body() public
Get/set the body for the message.
-
cookie() public
Get/Set cookie values.
-
cookies() public
Get all cookies
-
header() public
Get/Set headers into the request.
-
headers() public
Get all headers
-
method() public
Get/Set the HTTP method.
-
url() public
Get/Set the url for the request.
-
version() public
Get/Set HTTP version.
Method Detail
_normalizeHeader() ¶ protected
_normalizeHeader(string $name): string
Normalize header names to Camel-Case form.
Parameters
-
string$name The header name to normalize.
Returns
stringNormalized header name.
body() ¶ public
body(string|null $body = null): mixed
Get/set the body for the message.
Parameters
-
string|null$body optional The body for the request. Leave null for get
Returns
mixedEither $this or the body value.
cookie() ¶ public
cookie(string $name, string|null $value = null): mixed
Get/Set cookie values.
Getting a cookie
$request->cookie('session');
Setting one cookie
$request->cookie('session', '123456');
Setting multiple headers
$request->cookie(['test' => 'value', 'split' => 'banana']);
Parameters
-
string$name The name of the cookie to get/set
-
string|null$value optional Either the value or null when getting values.
Returns
mixedEither $this or the cookie value.
header() ¶ public
header(string|array|null $name = null, string|null $value = null): mixed
Get/Set headers into the request.
You can get the value of a header, or set one/many headers. Headers are set / fetched in a case insensitive way.
Getting headers
$request->header('Content-Type');
Setting one header
$request->header('Content-Type', 'application/json');
Setting multiple headers
$request->header(['Connection' => 'close', 'User-Agent' => 'CakePHP']);
Parameters
-
string|array|null$name optional The name to get, or array of multiple values to set.
-
string|null$value optional The value to set for the header.
Returns
mixedEither $this when setting or header value when getting.
method() ¶ public
method(string|null $method = null): $this|string
Get/Set the HTTP method.
Parameters
-
string|null$method optional The method for the request.
Returns
$this|stringEither this or the current method.
Throws
Cake\Core\Exception\ExceptionOn invalid methods.
url() ¶ public
url(string|null $url = null): $this|string
Get/Set the url for the request.
Parameters
-
string|null$url optional The url for the request. Leave null for get
Returns
$this|stringEither $this or the url value.
version() ¶ public
version(string|null $version = null): $this|string
Get/Set HTTP version.
Parameters
-
string|null$version optional The HTTP version.
Returns
$this|stringEither $this or the HTTP version.