Constants

STATE_NEW

STATE_NEW = 'new'

STATE_COMPLETE

STATE_COMPLETE = 'complete'

STATE_TRANSFER

STATE_TRANSFER = 'transfer'

STATE_ERROR

STATE_ERROR = 'error'

GET

GET = 'GET'

PUT

PUT = 'PUT'

POST

POST = 'POST'

DELETE

DELETE = 'DELETE'

HEAD

HEAD = 'HEAD'

CONNECT

CONNECT = 'CONNECT'

OPTIONS

OPTIONS = 'OPTIONS'

TRACE

TRACE = 'TRACE'

PATCH

PATCH = 'PATCH'

URL_ENCODED

URL_ENCODED = 'application/x-www-form-urlencoded; charset=utf-8'

MULTIPART

MULTIPART = 'multipart/form-data'

Methods

__toString()

__toString() : string

Returns

string

send()

send() : \Guzzle\Http\Message\Response

Send the request

Throws

\Guzzle\Http\Exception\RequestException

on a request error

Returns

\Guzzle\Http\Message\Response

setClient()

setClient(\Guzzle\Http\ClientInterface  $client) : self

Set the client used to transport the request

Parameters

\Guzzle\Http\ClientInterface $client

Returns

self

getClient()

getClient() : \Guzzle\Http\ClientInterface

Get the client used to transport the request

Returns

\Guzzle\Http\ClientInterface

$client

setUrl()

setUrl(  $url) : self

Set the URL of the request

Parameters

$url

Returns

self

getUrl()

getUrl(boolean  $asObject = false) : string|\Guzzle\Http\Url

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

Parameters

boolean $asObject

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

Returns

string|\Guzzle\Http\Url

getResource()

getResource() : string

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

Returns

string

getQuery()

getQuery() : \Guzzle\Http\QueryString

Get the collection of key value pairs that will be used as the query string in the request

Returns

\Guzzle\Http\QueryString

getMethod()

getMethod() : string

Get the HTTP method of the request

Returns

string

getScheme()

getScheme() : string

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

Returns

string

setScheme()

setScheme(string  $scheme) : self

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

Parameters

string $scheme

Scheme to set

Returns

self

getHost()

getHost() : string

Get the host of the request

Returns

string

setHost()

setHost(string  $host) : self

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

Parameters

string $host

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

Returns

self

getPath()

getPath() : string

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

Returns

string

setPath()

setPath(string|array  $path) : self

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

Parameters

string|array $path

Path to set or array of segments to implode

Returns

self

getPort()

getPort() : integer|null

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

Returns

integer|null

setPort()

setPort(integer  $port) : self

Set the port that the request will be sent on

Parameters

integer $port

Port number to set

Returns

self

getUsername()

getUsername() : string|null

Get the username to pass in the URL if set

Returns

string|null

getPassword()

getPassword() : string|null

Get the password to pass in the URL if set

Returns

string|null

setAuth()

setAuth(string|boolean  $user, string  $password = '', string  $scheme = 'Basic') : self

Set HTTP authorization parameters

Parameters

string|boolean $user

User name or false disable authentication

string $password

Password

string $scheme

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

Throws

\Guzzle\Http\Exception\RequestException

Returns

self

getProtocolVersion()

getProtocolVersion() : string

Get the HTTP protocol version of the request

Returns

string

setProtocolVersion()

setProtocolVersion(string  $protocol) : self

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

Parameters

string $protocol

HTTP protocol version to use with the request

Returns

self

getResponse()

getResponse() : \Guzzle\Http\Message\Response|null

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

Returns

\Guzzle\Http\Message\Response|null

setResponse()

setResponse(\Guzzle\Http\Message\Response  $response, boolean  $queued = false) : self

Manually set a response for the request.

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

\Guzzle\Http\Message\Response $response

Response object to set

boolean $queued

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

Returns

self —

Returns a reference to the object.

startResponse()

startResponse(\Guzzle\Http\Message\Response  $response) : self

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

Parameters

\Guzzle\Http\Message\Response $response

Response that has been received so far

Returns

self

setResponseBody()

setResponseBody(\Guzzle\Http\EntityBodyInterface|string|resource  $body) : \Guzzle\Http\Message\Request

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

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

\Guzzle\Http\EntityBodyInterface|string|resource $body

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

Returns

\Guzzle\Http\Message\Request

getResponseBody()

getResponseBody() : \Guzzle\Http\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.

Returns

\Guzzle\Http\EntityBodyInterface

getState()

getState() : string

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

Returns

string

setState()

setState(string  $state, array  $context = array()) : string

Set the state of the request

Parameters

string $state

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

array $context

Contextual information about the state change

Returns

string —

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

getCurlOptions()

getCurlOptions() : \Guzzle\Common\Collection

Get the cURL options that will be applied when the cURL handle is created

Returns

\Guzzle\Common\Collection

getCookies()

getCookies() : array

Get an array of Cookies

Returns

array

getCookie()

getCookie(string  $name) : null|string

Get a cookie value by name

Parameters

string $name

Cookie to retrieve

Returns

null|string

addCookie()

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

Add a Cookie value by name to the Cookie header

Parameters

string $name

Name of the cookie to add

string $value

Value to set

Returns

self

removeCookie()

removeCookie(string  $name) : self

Remove a specific cookie value by name

Parameters

string $name

Cookie to remove by name

Returns

self

getParams()

getParams() : \Guzzle\Common\Collection

Get application and plugin specific parameters set on the message.

Returns

\Guzzle\Common\Collection

addHeader()

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

Add a header to an existing collection of headers.

Parameters

string $header

Header name to add

string $value

Value of the header

Returns

self

addHeaders()

addHeaders(array  $headers) : self

Add and merge in an array of HTTP headers.

Parameters

array $headers

Associative array of header data.

Returns

self

getHeader()

getHeader(string  $header) : \Guzzle\Http\Message\Header|null

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

Parameters

string $header

Header to retrieve.

Returns

\Guzzle\Http\Message\Header|null

hasHeader()

hasHeader(string  $header) : boolean

Check if the specified header is present.

Parameters

string $header

The header to check.

Returns

boolean

removeHeader()

removeHeader(string  $header) : self

Remove a specific HTTP header.

Parameters

string $header

HTTP header to remove.

Returns

self

setHeader()

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

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

Parameters

string $header

Name of the header to set.

mixed $value

Value to set.

Returns

self

setHeaders()

setHeaders(array  $headers) : self

Overwrite all HTTP headers with the supplied array of headers

Parameters

array $headers

Associative array of header data.

Returns

self

getHeaderLines()

getHeaderLines() : array

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

..])

Returns

array

getRawHeaders()

getRawHeaders() : string

Get the raw message headers as a string

Returns

string

getAllEvents()

getAllEvents() : array

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

Returns

array

dispatch()

dispatch(string  $eventName, array  $context = array()) : \Guzzle\Common\Event

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

Parameters

string $eventName

Name of the event to dispatch

array $context

Context of the event

Returns

\Guzzle\Common\Event

Returns the created event object

setBody()

setBody(string|resource|\Guzzle\Http\EntityBodyInterface  $body, string  $contentType = null) : self

Set the body of the request

Parameters

string|resource|\Guzzle\Http\EntityBodyInterface $body

Body to use in the entity body of the request

string $contentType

Content-Type to set. Leave null to use an existing Content-Type or to guess the Content-Type

Throws

\Guzzle\Http\Exception\RequestException

if the protocol is < 1.1 and Content-Length can not be determined

Returns

self

getPostField()

getPostField(string  $field) : mixed|null

Get a POST field from the request

Parameters

string $field

Field to retrieve

Returns

mixed|null

getPostFields()

getPostFields() : \Guzzle\Http\QueryString

Get the post fields that will be used in the request

Returns

\Guzzle\Http\QueryString

setPostField()

setPostField(string  $key, string  $value) : self

Set a POST field value

Parameters

string $key

Key to set

string $value

Value to set

Returns

self

addPostFields()

addPostFields(\Guzzle\Http\QueryString|array  $fields) : self

Add POST fields to use in the request

Parameters

\Guzzle\Http\QueryString|array $fields

POST fields

Returns

self

removePostField()

removePostField(string  $field) : self

Remove a POST field or file by name

Parameters

string $field

Name of the POST field or file to remove

Returns

self

getPostFiles()

getPostFiles() : array

Returns an associative array of POST field names to PostFileInterface objects

Returns

array

getPostFile()

getPostFile(string  $fieldName) : array|null

Get a POST file from the request

Parameters

string $fieldName

POST fields to retrieve

Returns

array|null —

Returns an array wrapping an array of PostFileInterface objects

removePostFile()

removePostFile(string  $fieldName) : self

Remove a POST file from the request

Parameters

string $fieldName

POST file field name to remove

Returns

self

addPostFile()

addPostFile(string  $field, string  $filename = null, string  $contentType = null, string  $postname = null) : self

Add a POST file to the upload

Parameters

string $field

POST field to use (e.g. file). Used to reference content from the server.

string $filename

Full path to the file. Do not include the @ symbol.

string $contentType

Optional Content-Type to add to the Content-Disposition. Default behavior is to guess. Set to false to not specify.

string $postname

The name of the file, when posted. (e.g. rename the file)

Returns

self

addPostFiles()

addPostFiles(array  $files) : self

Add POST files to use in the upload

Parameters

array $files

An array of POST fields => filenames where filename can be a string or PostFileInterface

Returns

self

configureRedirects()

configureRedirects(boolean  $strict = false, integer  $maxRedirects = 5) : self

Configure how redirects are handled for the request

Parameters

boolean $strict

Set to true to follow strict RFC compliance when redirecting POST requests. Most browsers with follow a 301-302 redirect for a POST request with a GET request. This is the default behavior of Guzzle. Enable strict redirects to redirect these responses with a POST rather than a GET request.

integer $maxRedirects

Specify the maximum number of allowed redirects. Set to 0 to disable redirects.

Returns

self