Class Request
Implements methods for HTTP requests.
Used by Cake\Http\Client to contain request information for making requests.
- Cake\Http\Client\Message
-   Cake\Http\Client\Request implements Psr\Http\Message\RequestInterface uses Zend\Diactoros\MessageTrait , Zend\Diactoros\RequestTrait Cake\Http\Client\Request implements Psr\Http\Message\RequestInterface uses Zend\Diactoros\MessageTrait , Zend\Diactoros\RequestTrait
Inherited Constants
-  METHOD_DELETE,METHOD_GET,METHOD_HEAD,METHOD_OPTIONS,METHOD_PATCH,METHOD_POST,METHOD_PUT,METHOD_TRACE,STATUS_ACCEPTED,STATUS_CREATED,STATUS_FOUND,STATUS_MOVED_PERMANENTLY,STATUS_OK,STATUS_SEE_OTHER,STATUS_TEMPORARY_REDIRECT
Inherited Properties
Method Summary
-  __construct() publicConstructor
-  addHeaders() protectedAdd an array of headers to the request.
-  body() publicGet/set the body/payload for the message.
-  cookie() publicGet/Set cookie values.
-  header() publicGet/Set headers into the request.
-  method() publicGet/Set the HTTP method.
-  url() publicGet/Set the url for the request.
-  version() publicGet/Set HTTP version.
Method Detail
__construct()source public
__construct( string $url '' , string $method self::METHOD_GET , array $headers [] , array|string|null $data null )
Constructor
Provides backwards compatible defaults for some properties.
Parameters
-  string $urloptional ''
- The request URL
-  string $methodoptional self::METHOD_GET
- The HTTP method to use.
-  array $headersoptional []
- The HTTP headers to set.
-  array|string|null $dataoptional null
- The request body to use.
addHeaders()source protected
addHeaders( array $headers )
Add an array of headers to the request.
Parameters
-  array $headers
- The headers to add.
body()source public
body( string|array|null $body null )
Get/set the body/payload for the message.
Array data will be serialized with Cake\Http\FormData, and the content-type will be set.
Parameters
-  string|array|null $bodyoptional null
- The body for the request. Leave null for get
Returns
mixedEither $this or the body value.
Overrides
Cake\Http\Client\Message::body()  cookie()source public
cookie( string $name , string|null $value null )
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 $valueoptional null
- Either the value or null when getting values.
Returns
mixedEither $this or the cookie value.
header()source public
header( string|array|null $name null , string|null $value null )
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']);
Warning This method mutates the request in-place for backwards compatibility reasons, and is not part of the PSR7 interface.
Deprecated
3.3.0 Use withHeader() and getHeaderLine() instead.Parameters
-  string|array|null $nameoptional null
- The name to get, or array of multiple values to set.
-  string|null $valueoptional null
- The value to set for the header.
Returns
mixedEither $this when setting or header value when getting.
method()source public
method( string|null $method null )
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.
Deprecated
3.3.0 Use getMethod() and withMethod() instead.Parameters
-  string|null $methodoptional null
- The method for the request.
Returns
$this|string Either this or the current method.
Throws
Cake\Core\Exception\ExceptionOn invalid methods.
url()source public
url( string|null $url null )
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.
Deprecated
3.3.0 Use getUri() and withUri() instead.Parameters
-  string|null $urloptional null
- The url for the request. Leave null for get
Returns
$this|string Either $this or the url value.
version()source public
version( string|null $version null )
Get/Set HTTP version.
Warning This method mutates the request in-place for backwards compatibility reasons, and is not part of the PSR7 interface.
Deprecated
3.3.0 Use getProtocolVersion() and withProtocolVersion() instead.Parameters
-  string|null $versionoptional null
- The HTTP version.
Returns
$this|string Either $this or the HTTP version.
Methods inherited from Cake\Http\Client\Message
headers()source public
headers( )
Get all headers
Deprecated
3.3.0 Use getHeaders() instead.Returns
array
    © 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
    https://api.cakephp.org/3.3/class-Cake.Http.Client.Request.html