Documentation

RequestInterface extends MessageInterface, HasDispatcherInterface

Generic HTTP request interface

Table of Contents

Constants

CONNECT  = 'CONNECT'
DELETE  = 'DELETE'
GET  = 'GET'
HEAD  = 'HEAD'
OPTIONS  = 'OPTIONS'
PATCH  = 'PATCH'
POST  = 'POST'
PUT  = 'PUT'
STATE_COMPLETE  = 'complete'
STATE_ERROR  = 'error'
STATE_NEW  = 'new'
STATE_TRANSFER  = 'transfer'
TRACE  = 'TRACE'

Methods

__toString()  : string
addCookie()  : self
Add a Cookie value by name to the Cookie header
addHeader()  : self
Add a header to an existing collection of headers.
addHeaders()  : self
Add and merge in an array of HTTP headers.
addSubscriber()  : self
Add an event subscriber to the dispatcher
dispatch()  : Event
Helper to dispatch Guzzle events and set the event name on the event
getAllEvents()  : array<string|int, mixed>
Get a list of all of the events emitted from the class
getClient()  : ClientInterface
Get the client used to transport the request
getCookie()  : null|string
Get a cookie value by name
getCookies()  : array<string|int, mixed>
Get an array of Cookies
getCurlOptions()  : Collection
Get the cURL options that will be applied when the cURL handle is created
getEventDispatcher()  : EventDispatcherInterface
Get the EventDispatcher of the request
getHeader()  : Header|null
Retrieve an HTTP header by name. Performs a case-insensitive search of all headers.
getHeaderLines()  : array<string|int, mixed>
Get an array of message header lines (e.g. ["Host: example.com", ...])
getHeaders()  : HeaderCollection
Get all headers as a collection
getHost()  : string
Get the host of the request
getMethod()  : string
Get the HTTP method of the request
getParams()  : Collection
Get application and plugin specific parameters set on the message.
getPassword()  : string|null
Get the password to pass in the URL if set
getPath()  : string
Get the path of the request (e.g. '/', '/index.html')
getPort()  : int|null
Get the port that the request will be sent on if it has been set
getProtocolVersion()  : string
Get the HTTP protocol version of the request
getQuery()  : QueryString
Get the collection of key value pairs that will be used as the query string in the request
getRawHeaders()  : string
Get the raw message headers as a string
getResource()  : string
Get the resource part of the the request, including the path, query string, and fragment
getResponse()  : Response|null
Get the previously received {@see Response} or NULL if the request has not been sent
getResponseBody()  : EntityBodyInterface
Get the EntityBody that will hold the resulting response message's entity body. This response body will only be used for successful responses. Intermediate responses (e.g. redirects) will not use the targeted response body.
getScheme()  : string
Get the URI scheme of the request (http, https, ftp, etc)
getState()  : string
Get the state of the request. One of 'complete', 'transfer', 'new', 'error'
getUrl()  : string|Url
Get the full URL of the request (e.g. 'http://www.guzzle-project.com/')
getUsername()  : string|null
Get the username to pass in the URL if set
hasHeader()  : bool
Check if the specified header is present.
removeCookie()  : self
Remove a specific cookie value by name
removeHeader()  : self
Remove a specific HTTP header.
send()  : Response
Send the request
setAuth()  : self
Set HTTP authorization parameters
setClient()  : self
Set the client used to transport the request
setEventDispatcher()  : self
Set the EventDispatcher of the request
setHeader()  : self
Set an HTTP header and overwrite any existing value for the header
setHeaders()  : self
Overwrite all HTTP headers with the supplied array of headers
setHost()  : self
Set the host of the request. Including a port in the host will modify the port of the request.
setPath()  : self
Set the path of the request (e.g. '/', '/index.html')
setPort()  : self
Set the port that the request will be sent on
setProtocolVersion()  : self
Set the HTTP protocol version of the request (e.g. 1.1 or 1.0)
setResponse()  : self
Manually set a response for the request.
setResponseBody()  : Request
Set the EntityBody that will hold a successful response message's entity body.
setScheme()  : self
Set the URI scheme of the request (http, https, ftp, etc)
setState()  : string
Set the state of the request
setUrl()  : self
Set the URL of the request
startResponse()  : self
The start of a response has been received for a request and the request is still in progress

Constants

Methods

addCookie()

Add a Cookie value by name to the Cookie header

public addCookie(string $name, string $value) : self
Parameters
$name : string

Name of the cookie to add

$value : string

Value to set

Return values
self

addHeader()

Add a header to an existing collection of headers.

public addHeader(string $header, string $value) : self
Parameters
$header : string

Header name to add

$value : string

Value of the header

Return values
self

addHeaders()

Add and merge in an array of HTTP headers.

public addHeaders(array<string|int, mixed> $headers) : self
Parameters
$headers : array<string|int, mixed>

Associative array of header data.

Return values
self

dispatch()

Helper to dispatch Guzzle events and set the event name on the event

public dispatch(string $eventName[, array<string|int, mixed> $context = array() ]) : Event
Parameters
$eventName : string

Name of the event to dispatch

$context : array<string|int, mixed> = array()

Context of the event

Return values
Event

Returns the created event object

getAllEvents()

Get a list of all of the events emitted from the class

public static getAllEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>

getCookie()

Get a cookie value by name

public getCookie(string $name) : null|string
Parameters
$name : string

Cookie to retrieve

Return values
null|string

getCookies()

Get an array of Cookies

public getCookies() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHeader()

Retrieve an HTTP header by name. Performs a case-insensitive search of all headers.

public getHeader(string $header) : Header|null
Parameters
$header : string

Header to retrieve.

Return values
Header|null

getHeaderLines()

Get an array of message header lines (e.g. ["Host: example.com", ...])

public getHeaderLines() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHost()

Get the host of the request

public getHost() : string
Return values
string

getMethod()

Get the HTTP method of the request

public getMethod() : string
Return values
string

getPassword()

Get the password to pass in the URL if set

public getPassword() : string|null
Return values
string|null

getPath()

Get the path of the request (e.g. '/', '/index.html')

public getPath() : string
Return values
string

getPort()

Get the port that the request will be sent on if it has been set

public getPort() : int|null
Return values
int|null

getProtocolVersion()

Get the HTTP protocol version of the request

public getProtocolVersion() : string
Return values
string

getRawHeaders()

Get the raw message headers as a string

public getRawHeaders() : string
Return values
string

getResource()

Get the resource part of the the request, including the path, query string, and fragment

public getResource() : string
Return values
string

getResponse()

Get the previously received {@see Response} or NULL if the request has not been sent

public getResponse() : Response|null
Return values
Response|null

getResponseBody()

Get the EntityBody that will hold the resulting response message's entity body. This response body will only be used for successful responses. Intermediate responses (e.g. redirects) will not use the targeted response body.

public getResponseBody() : EntityBodyInterface
Return values
EntityBodyInterface

getScheme()

Get the URI scheme of the request (http, https, ftp, etc)

public getScheme() : string
Return values
string

getState()

Get the state of the request. One of 'complete', 'transfer', 'new', 'error'

public getState() : string
Return values
string

getUrl()

Get the full URL of the request (e.g. 'http://www.guzzle-project.com/')

public getUrl([bool $asObject = false ]) : string|Url
Parameters
$asObject : bool = false

Set to TRUE to retrieve the URL as a clone of the URL object owned by the request.

Return values
string|Url

getUsername()

Get the username to pass in the URL if set

public getUsername() : string|null
Return values
string|null

hasHeader()

Check if the specified header is present.

public hasHeader(string $header) : bool
Parameters
$header : string

The header to check.

Return values
bool

removeCookie()

Remove a specific cookie value by name

public removeCookie(string $name) : self
Parameters
$name : string

Cookie to remove by name

Return values
self

removeHeader()

Remove a specific HTTP header.

public removeHeader(string $header) : self
Parameters
$header : string

HTTP header to remove.

Return values
self

setAuth()

Set HTTP authorization parameters

public setAuth(string|bool $user[, string $password = '' ][, string $scheme = 'Basic' ]) : self
Parameters
$user : string|bool

User name or false disable authentication

$password : string = ''

Password

$scheme : string = 'Basic'

Authentication scheme ('Basic', 'Digest', or a CURLAUTH_* constant (deprecated))

Tags
link
http://www.ietf.org/rfc/rfc2617.txt
link

See the available options for CURLOPT_HTTPAUTH

throws
RequestException
Return values
self

setHeader()

Set an HTTP header and overwrite any existing value for the header

public setHeader(string $header, mixed $value) : self
Parameters
$header : string

Name of the header to set.

$value : mixed

Value to set.

Return values
self

setHeaders()

Overwrite all HTTP headers with the supplied array of headers

public setHeaders(array<string|int, mixed> $headers) : self
Parameters
$headers : array<string|int, mixed>

Associative array of header data.

Return values
self

setHost()

Set the host of the request. Including a port in the host will modify the port of the request.

public setHost(string $host) : self
Parameters
$host : string

Host to set (e.g. www.yahoo.com, www.yahoo.com:80)

Return values
self

setPath()

Set the path of the request (e.g. '/', '/index.html')

public setPath(string|array<string|int, mixed> $path) : self
Parameters
$path : string|array<string|int, mixed>

Path to set or array of segments to implode

Return values
self

setPort()

Set the port that the request will be sent on

public setPort(int $port) : self
Parameters
$port : int

Port number to set

Return values
self

setProtocolVersion()

Set the HTTP protocol version of the request (e.g. 1.1 or 1.0)

public setProtocolVersion(string $protocol) : self
Parameters
$protocol : string

HTTP protocol version to use with the request

Return values
self

setResponse()

Manually set a response for the request.

public setResponse(Response $response[, bool $queued = false ]) : self

This method is useful for specifying a mock response for the request or setting the response using a cache. Manually setting a response will bypass the actual sending of a request.

Parameters
$response : Response

Response object to set

$queued : bool = false

Set to TRUE to keep the request in a state of not having been sent, but queue the response for send()

Return values
self

Returns a reference to the object.

setResponseBody()

Set the EntityBody that will hold a successful response message's entity body.

public setResponseBody(EntityBodyInterface|string|resource $body) : Request

This method should be invoked when you need to send the response's entity body somewhere other than the normal php://temp buffer. For example, you can send the entity body to a socket, file, or some other custom stream.

Parameters
$body : EntityBodyInterface|string|resource

Response body object. Pass a string to attempt to store the response body in a local file.

Return values
Request

setScheme()

Set the URI scheme of the request (http, https, ftp, etc)

public setScheme(string $scheme) : self
Parameters
$scheme : string

Scheme to set

Return values
self

setState()

Set the state of the request

public setState(string $state[, array<string|int, mixed> $context = array() ]) : string
Parameters
$state : string

State of the request ('complete', 'transfer', 'new', 'error')

$context : array<string|int, mixed> = array()

Contextual information about the state change

Return values
string

Returns the current state of the request (which may have changed due to events being fired)

setUrl()

Set the URL of the request

public setUrl(string $url) : self
Parameters
$url : string

|Url Full URL to set including query string

Return values
self

startResponse()

The start of a response has been received for a request and the request is still in progress

public startResponse(Response $response) : self
Parameters
$response : Response

Response that has been received so far

Return values
self

        
On this page

Search results