STATUS_OK
STATUS_OK = 200 : integer
HTTP 200 code
Implements methods for HTTP requests.
Used by Cake\Http\Client to contain request information for making requests.
$uri : \Psr\Http\Message\UriInterface
getRequestTarget() : string
Retrieves the message's request target.
Retrieves the message's request-target either as it will appear (for clients), as it appeared at request (for servers), or as it was specified for the instance (see withRequestTarget()).
In most cases, this will be the origin-form of the composed URI, unless a value was provided to the concrete implementation (see withRequestTarget() below).
If no URI is available, and no request-target has been specifically provided, this method MUST return the string "/".
withRequestTarget(mixed $requestTarget) : static
Create a new instance with a specific request-target.
If the request needs a non-origin-form request-target — e.g., for specifying an absolute-form, authority-form, or asterisk-form — this method may be used to create an instance with the specified request-target, verbatim.
This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return a new instance that has the changed request target.
mixed | $requestTarget |
if the request target is invalid.
withMethod(string $method) : static
Return an instance with the provided HTTP method.
While HTTP method names are typically all uppercase characters, HTTP method names are case-sensitive and thus implementations SHOULD NOT modify the given string.
This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the changed request method.
string | $method | Case-insensitive method. |
for invalid HTTP methods.
getUri() : \Psr\Http\Message\UriInterface
Retrieves the URI instance.
This method MUST return a UriInterface instance.
Returns a UriInterface instance representing the URI of the request, if any.
withUri(\Psr\Http\Message\UriInterface $uri, boolean $preserveHost = false) : static
Returns an instance with the provided URI.
This method will update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header will be carried over to the returned request.
You can opt-in to preserving the original state of the Host header by
setting $preserveHost
to true
. When $preserveHost
is set to
true
, the returned request will not update the Host header of the
returned message -- even if the message contains no Host header. This
means that a call to getHeader('Host')
on the original request MUST
equal the return value of a call to getHeader('Host')
on the returned
request.
This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new UriInterface instance.
\Psr\Http\Message\UriInterface | $uri | New request URI to use. |
boolean | $preserveHost | Preserve the original state of the Host header. |
None found |
body(string|array|null $body = null) : mixed
Get/set the body/payload for the message.
Array data will be serialized with Cake\Http\FormData, and the content-type will be set.
string|array|null | $body | The body for the request. Leave null for get |
Either $this or the body value.
None found |
__construct(string $url = '', string $method = self::METHOD_GET, array $headers = array(), array|string|null $data = null)
Constructor
Provides backwards compatible defaults for some properties.
string | $url | The request URL |
string | $method | The HTTP method to use. |
array | $headers | The HTTP headers to set. |
array|string|null | $data | The request body to use. |
None found |
method(string|null $method = null) : $this|string
Get/Set the HTTP method.
Warning This method mutates the request in-place for backwards compatibility reasons, and is not part of the PSR7 interface.
string|null | $method | The method for the request. |
On invalid methods.
Either this or the current method.
None found |
url(string|null $url = null) : $this|string
Get/Set the url for the request.
Warning This method mutates the request in-place for backwards compatibility reasons, and is not part of the PSR7 interface.
string|null | $url | The url for the request. Leave null for get |
Either $this or the url value.
None found |
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.
$request->header('Content-Type');
$request->header('Content-Type', 'application/json');
$request->header(['Connection' => 'close', 'User-Agent' => 'CakePHP']);
Warning This method mutates the request in-place for backwards compatibility reasons, and is not part of the PSR7 interface.
string|array|null | $name | The name to get, or array of multiple values to set. |
string|null | $value | The value to set for the header. |
Either $this when setting or header value when getting.
None found |
cookie(string $name, string|null $value = null) : mixed
Get/Set cookie values.
$request->cookie('session');
$request->cookie('session', '123456');
$request->cookie(['test' => 'value', 'split' => 'banana']);
string | $name | The name of the cookie to get/set |
string|null | $value | Either the value or null when getting values. |
Either $this or the cookie value.
None found |
version(string|null $version = null) : $this|string
Get/Set HTTP version.
Warning This method mutates the request in-place for backwards compatibility reasons, and is not part of the PSR7 interface.
string|null | $version | The HTTP version. |
Either $this or the HTTP version.
None found |
addHeaders(array $headers) : void
Add an array of headers to the request.
array | $headers | The headers to add. |
None found |
initialize(null|string|\Psr\Http\Message\UriInterface $uri = null, null|string $method = null, string|resource|\Psr\Http\Message\StreamInterface $body = 'php://memory', array $headers = array())
Initialize request state.
Used by constructors.
null|string|\Psr\Http\Message\UriInterface | $uri | URI for the request, if any. |
null|string | $method | HTTP method for the request, if any. |
string|resource|\Psr\Http\Message\StreamInterface | $body | Message body, if any. |
array | $headers | Headers for the message, if any. |
for any invalid value.
None found |
createUri(null|string|\Psr\Http\Message\UriInterface $uri) : \Psr\Http\Message\UriInterface
Create and return a URI instance.
If $uri
is a already a UriInterface
instance, returns it.
If $uri
is a string, passes it to the Uri
constructor to return an
instance.
If $uri is null, creates and returns an empty
Uri` instance.
Otherwise, it raises an exception.
null|string|\Psr\Http\Message\UriInterface | $uri |
None found |
validateMethod(null|string $method)
Validate the HTTP method
null|string | $method |
on invalid HTTP method.
None found |
None found |