CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.1 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.1
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • I18n
    • Log
    • Mailer
    • Network
      • Exception
      • Http
        • Adapter
        • Auth
        • FormData
      • Session
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class Request

Implements methods for HTTP requests.

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

Namespace: Cake\Network\Http

Constants

  • string
    METHOD_DELETE ¶
    'DELETE'

    HTTP DELETE method

  • string
    METHOD_GET ¶
    'GET'

    HTTP GET method

  • string
    METHOD_HEAD ¶
    'HEAD'

    HTTP HEAD method

  • string
    METHOD_OPTIONS ¶
    'OPTIONS'

    HTTP OPTIONS method

  • string
    METHOD_PATCH ¶
    'PATCH'

    HTTP PATCH method

  • string
    METHOD_POST ¶
    'POST'

    HTTP POST method

  • string
    METHOD_PUT ¶
    'PUT'

    HTTP PUT method

  • string
    METHOD_TRACE ¶
    'TRACE'

    HTTP TRACE method

  • int
    STATUS_ACCEPTED ¶
    202

    HTTP 202 code

  • int
    STATUS_CREATED ¶
    201

    HTTP 201 code

  • int
    STATUS_FOUND ¶
    302

    HTTP 302 code

  • int
    STATUS_MOVED_PERMANENTLY ¶
    301

    HTTP 301 code

  • int
    STATUS_OK ¶
    200

    HTTP 200 code

  • int
    STATUS_SEE_OTHER ¶
    303

    HTTP 303 code

  • int
    STATUS_TEMPORARY_REDIRECT ¶
    307

    HTTP 307 code

Property Summary

  • $_body protected
    mixed

    Request body to send.

  • $_cookies protected
    array

    The array of cookies in the response.

  • $_headers protected
    array

    Headers to be sent.

  • $_method protected
    string

    The HTTP method to use.

  • $_url protected
    string

    The URL to request.

  • $_version protected
    string

    HTTP Version being used.

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
string

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
mixed

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
mixed

cookies() ¶ public

cookies(): array

Get all cookies

Returns
array

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
mixed

headers() ¶ public

headers(): array

Get all headers

Returns
array

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|string
Throws
Cake\Core\Exception\Exception
On 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|string

version() ¶ public

version(string|null $version = null): $this|string

Get/Set HTTP version.

Parameters
string|null $version optional

The HTTP version.

Returns
$this|string

Property Detail

$_body ¶ protected

Request body to send.

Type
mixed

$_cookies ¶ protected

The array of cookies in the response.

Type
array

$_headers ¶ protected

Headers to be sent.

Type
array

$_method ¶ protected

The HTTP method to use.

Type
string

$_url ¶ protected

The URL to request.

Type
string

$_version ¶ protected

HTTP Version being used.

Type
string
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs