Request (class)

Class Request

Implements methods for HTTP requests.

Used by Cake\Network\Http\Client to contain request information for making requests.

Cake\Network\Http\Message
Extended by Cake\Network\Http\Request
Namespace: Cake\Network\Http
Located at Network/Http/Request.php

Method Detail

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 $value optional null
Either the value or null when getting values.

Returns

mixed
Either $this or the cookie value.

headersource 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']);

Parameters

string|array|null $name optional null
The name to get, or array of multiple values to set.
string|null $value optional null
The value to set for the header.

Returns

mixed
Either $this when setting or header value when getting.

methodsource public

method( string|null $method null )

Get/Set the HTTP method.

Parameters

string|null $method optional null
The method for the request.

Returns

mixed
$this|string Either this or the current method.

Throws

Cake\Core\Exception\Exception
On invalid methods.

urlsource public

url( string|null $url null )

Get/Set the url for the request.

Parameters

string|null $url optional null
The url for the request. Leave null for get

Returns

mixed
$this|string Either $this or the url value.

versionsource public

version( string|null $version null )

Get/Set HTTP version.

Parameters

string|null $version optional null
The HTTP version.

Returns

mixed
$this|string Either $this or the HTTP version.

Overrides

Cake\Network\Http\Message::version()

Methods inherited from Cake\Network\Http\Message

_normalizeHeadersource protected

_normalizeHeader( string $name )

Normalize header names to Camel-Case form.

Parameters

string $name
The header name to normalize.

Returns

string
Normalized header name.

bodysource public

body( string|null $body null )

Get/set the body for the message.

Parameters

string|null $body optional null
The body for the request. Leave null for get

Returns

mixed
Either $this or the body value.

cookiessource public

cookies( )

Get all cookies

Returns

array
array

headerssource public

headers( )

Get all headers

Returns

array
array

Constants inherited from Cake\Network\Http\Message

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

Properties summary

$_bodysource

protected mixed

Request body to send.

$_headerssource

protected array

Headers to be sent.

[
    'Connection' => 'close',
    'User-Agent' => 'CakePHP'
]

$_methodsource

protected string

The HTTP method to use.

$_urlsource

protected string

The URL to request.

Properties inherited from Cake\Network\Http\Message

$_cookiessource

protected array

The array of cookies in the response.

[]

$_versionsource

protected string

HTTP Version being used.

'1.1'

© 2005–2016 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.
http://api.cakephp.org/3.1/class-Cake.Network.Http.Request.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部