\Guzzle\Http\MessageEntityEnclosingRequest

HTTP request that sends an entity-body in the request message (POST, PUT, PATCH, DELETE)

Summary

Methods
Properties
Constants
getAllEvents()
__construct()
__clone()
__toString()
onRequestError()
setClient()
getClient()
getRawHeaders()
setUrl()
send()
getResponse()
getQuery()
getMethod()
getScheme()
setScheme()
getHost()
setHost()
getProtocolVersion()
setProtocolVersion()
getPath()
setPath()
getPort()
setPort()
getUsername()
getPassword()
setAuth()
getResource()
getUrl()
getState()
setState()
getCurlOptions()
startResponse()
setResponse()
setResponseBody()
getResponseBody()
isResponseBodyRepeatable()
getCookies()
getCookie()
addCookie()
removeCookie()
setEventDispatcher()
getEventDispatcher()
dispatch()
addSubscriber()
canCache()
setIsRedirect()
isRedirect()
setHeaderFactory()
getParams()
addHeader()
addHeaders()
getHeader()
getHeaders()
getHeaderLines()
setHeader()
setHeaders()
hasHeader()
removeHeader()
getTokenizedHeader()
setTokenizedHeader()
getCacheControlDirective()
hasCacheControlDirective()
addCacheControlDirective()
removeCacheControlDirective()
setBody()
getBody()
setExpectHeaderCutoff()
configureRedirects()
getPostField()
getPostFields()
setPostField()
addPostFields()
removePostField()
getPostFiles()
getPostFile()
removePostFile()
addPostFile()
addPostFiles()
No public properties found
No constants found
getEventArray()
processResponse()
processPostFields()
$eventDispatcher
$url
$method
$client
$response
$responseBody
$state
$username
$password
$curlOptions
$isRedirect
$headers
$headerFactory
$params
$protocol
$protocolVersion
$expectCutoff
$body
$postFields
$postFiles
N/A
No private methods found
No private properties found
N/A

Properties

$method

$method : string

Type

string — HTTP method (GET, PUT, POST, DELETE, HEAD, OPTIONS, TRACE)

$state

$state : string

Type

string — State of the request object

$username

$username : string

Type

string — Authentication username

$password

$password : string

Type

string — Auth password

$isRedirect

$isRedirect : boolean

Type

boolean

$headers

$headers : array

Type

array — HTTP header collection

$params

$params : \Guzzle\Common\Collection

Type

\Guzzle\Common\Collection — Custom message parameters that are extendable by plugins

$protocol

$protocol : string

Type

string — Message protocol

$protocolVersion

$protocolVersion : string

Type

string — HTTP protocol version of the message

$expectCutoff

$expectCutoff : integer

Type

integer — When the size of the body is greater than 1MB, then send Expect: 100-Continue

$postFields

$postFields : \Guzzle\Http\QueryString

Type

\Guzzle\Http\QueryString — POST fields to use in the EntityBody

$postFiles

$postFiles : array

Type

array — POST files to send with the request

Methods

getAllEvents()

getAllEvents() 

__construct()

__construct(string  $method, string|\Guzzle\Http\Url  $url, array|\Guzzle\Common\Collection  $headers = array()) 

Parameters

string $method

HTTP method

string|\Guzzle\Http\Url $url

HTTP URL to connect to. The URI scheme, host header, and URI are parsed from the full URL. If query string parameters are present they will be parsed as well.

array|\Guzzle\Common\Collection $headers

HTTP headers

__clone()

__clone() 

__toString()

__toString() : string

Get the HTTP request as a string

Returns

string

onRequestError()

onRequestError(\Guzzle\Common\Event  $event) 

Default method that will throw exceptions if an unsuccessful response is received.

Parameters

\Guzzle\Common\Event $event

Received

Throws

\Guzzle\Http\Exception\BadResponseException

if the response is not successful

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

getRawHeaders()

getRawHeaders() 

setUrl()

setUrl(  $url) : self

Set the URL of the request

Parameters

$url

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

getQuery()

getQuery(  $asString = false) : \Guzzle\Http\QueryString

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

Parameters

$asString

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

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

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 = CURLAUTH_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))

Returns

self

getResource()

getResource() : string

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

Returns

string

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

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

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

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.

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

isResponseBodyRepeatable()

isResponseBodyRepeatable() : boolean

Determine if the response body is repeatable (readable + seekable)

Returns

boolean

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

getEventDispatcher()

getEventDispatcher() 

dispatch()

dispatch(  $eventName, array  $context = array()) 

Parameters

$eventName
array $context

canCache()

canCache() 

setIsRedirect()

setIsRedirect(  $isRedirect) 

Parameters

$isRedirect

isRedirect()

isRedirect() 

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

getHeaderLines()

getHeaderLines() : array

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

..])

Returns

array

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

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

getTokenizedHeader()

getTokenizedHeader(  $header,   $token = ';') 

Parameters

$header
$token

setTokenizedHeader()

setTokenizedHeader(  $header,   $data,   $token = ';') 

Parameters

$header
$data
$token

getCacheControlDirective()

getCacheControlDirective(  $directive) 

Parameters

$directive

hasCacheControlDirective()

hasCacheControlDirective(  $directive) 

Parameters

$directive

addCacheControlDirective()

addCacheControlDirective(  $directive,   $value = true) 

Parameters

$directive
$value

removeCacheControlDirective()

removeCacheControlDirective(  $directive) 

Parameters

$directive

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

Returns

self

setExpectHeaderCutoff()

setExpectHeaderCutoff(integer|boolean  $size) : self

Set the size that the entity body of the request must exceed before adding the Expect: 100-Continue header.

Parameters

integer|boolean $size

Cutoff in bytes. Set to false to never send the expect header (even with non-seekable data)

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

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

getEventArray()

getEventArray() : array

Get an array containing the request and response for event notifications

Returns

array

processResponse()

processResponse(array  $context = array()) 

Process a received response

Parameters

array $context

Contextual information

Throws

\Guzzle\Http\Exception\RequestException|\Guzzle\Http\Exception\BadResponseException

on unsuccessful responses

processPostFields()

processPostFields() 

Determine what type of request should be sent based on post fields