Class Request
HTTP request class to send requests
- Guzzle\Http\Message\AbstractMessage implements Guzzle\Http\Message\MessageInterface
-
Guzzle\Http\Message\Request
implements
Guzzle\Http\Message\RequestInterface
Direct known subclasses
Methods summary
-
public staticgetAllEvents ( )Get a list of all of the events emitted from the class
-
public__construct ( string $method, string|Url $url, array|Collection $headers = array() ) -
public__clone ( ) -
public__toString ( )Get the HTTP request as a string
-
public staticonRequestError ( Guzzle\Common\Event $event )Default method that will throw exceptions if an unsuccessful response is received.
-
publicsetClient ( Guzzle\Http\ClientInterface $client )Set the client used to transport the request
-
publicgetClient ( )Get the client used to transport the request
-
publicgetRawHeaders ( )Get the raw message headers as a string
-
publicsetUrl ( string $url )Set the URL of the request
-
publicsend ( )Send the request
-
publicgetResponse ( )Get the previously received
Guzzle\Http\Message\Responseor NULL if the request has not been sent -
publicgetQuery ( mixed $asString = false )Get the collection of key value pairs that will be used as the query string in the request
-
publicgetMethod ( )Get the HTTP method of the request
-
publicgetScheme ( )Get the URI scheme of the request (http, https, ftp, etc)
-
publicsetScheme ( string $scheme )Set the URI scheme of the request (http, https, ftp, etc)
-
publicgetHost ( )Get the host of the request
-
publicsetHost ( string $host )Set the host of the request. Including a port in the host will modify the port of the request.
-
publicgetProtocolVersion ( )Get the HTTP protocol version of the request
-
publicsetProtocolVersion ( string $protocol )Set the HTTP protocol version of the request (e.g. 1.1 or 1.0)
-
publicgetPath ( )Get the path of the request (e.g. '/', '/index.html')
-
publicsetPath ( string|array $path )Set the path of the request (e.g. '/', '/index.html')
-
publicgetPort ( )Get the port that the request will be sent on if it has been set
-
publicsetPort ( int $port )Set the port that the request will be sent on
-
publicgetUsername ( )Get the username to pass in the URL if set
-
publicgetPassword ( )Get the password to pass in the URL if set
-
publicsetAuth ( string|bool $user, string $password = '', string $scheme = CURLAUTH_BASIC )Set HTTP authorization parameters
-
publicgetResource ( )Get the resource part of the the request, including the path, query string, and fragment
-
publicgetUrl ( bool $asObject = false )Get the full URL of the request (e.g. 'http://www.guzzle-project.com/')
-
publicgetState ( )Get the state of the request. One of 'complete', 'transfer', 'new', 'error'
-
publicsetState ( string $state, array $context = array() )Set the state of the request
-
publicgetCurlOptions ( )Get the cURL options that will be applied when the cURL handle is created
-
publicstartResponse ( Guzzle\Http\Message\Response $response )The start of a response has been received for a request and the request is still in progress
-
publicsetResponse ( Guzzle\Http\Message\Response $response, bool $queued = false )Manually set a response for the request.
-
publicsetResponseBody ( EntityBodyInterface|string|resource $body )Set the EntityBody that will hold a successful response message's entity body.
-
publicgetResponseBody ( )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.
-
publicgetCookies ( )Get an array of Cookies
-
publicgetCookie ( string $name )Get a cookie value by name
-
publicaddCookie ( string $name, string $value )Add a Cookie value by name to the Cookie header
-
publicremoveCookie ( string $name )Remove a specific cookie value by name
-
publicsetEventDispatcher ( Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher )Set the EventDispatcher of the request
-
publicgetEventDispatcher ( )Get the EventDispatcher of the request
-
publicdispatch ( string $eventName, array $context = array() )Helper to dispatch Guzzle events and set the event name on the event
-
publicaddSubscriber ( Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber )Add an event subscriber to the dispatcher
-
protectedgetEventArray ( )Get an array containing the request and response for event notifications
-
protectedprocessResponse ( array $context = array() )Process a received response
Methods detail
Get a list of all of the events emitted from the class
Returns
arrayImplementation of
public
__construct( string $method, string|Guzzle\Http\Url $url, array|Guzzle\Common\Collection $headers = array() )
Parameters
- $method
string
$method HTTP method- $url
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.- $headers
array|Guzzle\Common\Collection
$headers HTTP headers
Overrides
Get the HTTP request as a string
Returns
stringImplementation of
Default method that will throw exceptions if an unsuccessful response is received.
Parameters
- $event
Guzzle\Common\Event
$event Received
Throws
Set the client used to transport the request
Parameters
- $client
Guzzle\Http\ClientInterface
$client
Returns
Implementation of
Get the client used to transport the request
Returns
Implementation of
Get the raw message headers as a string
Returns
stringImplementation of
Set the URL of the request
Parameters
- $url
string
$url|Url Full URL to set including query string
Returns
Implementation of
Send the request
Returns
Throws
Implementation of
Get the previously received Guzzle\Http\Message\Response or NULL if the request has not
been sent
Returns
Implementation of
Get the collection of key value pairs that will be used as the query string in the request
Returns
QueryStringImplementation of
Get the HTTP method of the request
Returns
stringImplementation of
Get the URI scheme of the request (http, https, ftp, etc)
Returns
stringImplementation of
Set the URI scheme of the request (http, https, ftp, etc)
Parameters
- $scheme
string
$scheme Scheme to set
Returns
Implementation of
Get the host of the request
Returns
stringImplementation of
Set the host of the request. Including a port in the host will modify the port of the request.
Parameters
- $host
string
$host Host to set (e.g. www.yahoo.com, www.yahoo.com:80)
Returns
Implementation of
Get the HTTP protocol version of the request
Returns
stringImplementation of
Set the HTTP protocol version of the request (e.g. 1.1 or 1.0)
Parameters
- $protocol
string
$protocol HTTP protocol version to use with the request
Returns
Implementation of
Get the path of the request (e.g. '/', '/index.html')
Returns
stringImplementation of
Set the path of the request (e.g. '/', '/index.html')
Parameters
- $path
string|array
$path Path to set or array of segments to implode
Returns
Implementation of
Get the port that the request will be sent on if it has been set
Returns
integer|nullImplementation of
Set the port that the request will be sent on
Parameters
- $port
integer
$port Port number to set
Returns
Implementation of
Get the username to pass in the URL if set
Returns
string|nullImplementation of
Get the password to pass in the URL if set
Returns
string|nullImplementation of
public
Guzzle\Http\Message\Request
setAuth( string|boolean $user, string $password = '', string $scheme = CURLAUTH_BASIC )
Set HTTP authorization parameters
Parameters
- $user
string|boolean
$user User name or false disable authentication- $password
string
$password Password- $scheme
string
$scheme Authentication scheme ('Basic', 'Digest', or a CURLAUTH_* constant (deprecated))
Returns
Throws
Link
Implementation of
Get the resource part of the the request, including the path, query string, and fragment
Returns
stringImplementation of
Get the full URL of the request (e.g. 'http://www.guzzle-project.com/')
Parameters
- $asObject
boolean
$asObject Set to TRUE to retrieve the URL as a clone of the URL object owned by the request.
Returns
string|Guzzle\Http\UrlImplementation of
Get the state of the request. One of 'complete', 'transfer', 'new', 'error'
Returns
stringImplementation of
Set the state of the request
Parameters
- $state
string
$state State of the request ('complete', 'transfer', 'new', 'error')- $context
array
$context Contextual information about the state change
Returns
stringReturns the current state of the request (which may have changed due to events being fired)
Implementation of
Get the cURL options that will be applied when the cURL handle is created
Returns
Implementation of
The start of a response has been received for a request and the request is still in progress
Parameters
- $response
Guzzle\Http\Message\Response
$response Response that has been received so far
Returns
Implementation of
public
Guzzle\Http\Message\Request
setResponse( Guzzle\Http\Message\Response $response, boolean $queued = false )
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
- $response
Guzzle\Http\Message\Response
$response Response object to set- $queued
boolean
$queued Set to TRUE to keep the request in a state of not having been sent, but queue the response for send()
Returns
Implementation of
public
Guzzle\Http\Message\Request
setResponseBody( Guzzle\Http\EntityBodyInterface|string|resource $body )
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
- $body
Guzzle\Http\EntityBodyInterface|string|resource
$body Response body object. Pass a string to attempt to store the response body in a local file.
Returns
Implementation of
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
Implementation of
Get an array of Cookies
Returns
arrayImplementation of
Get a cookie value by name
Parameters
- $name
string
$name Cookie to retrieve
Returns
null|stringImplementation of
Add a Cookie value by name to the Cookie header
Parameters
- $name
string
$name Name of the cookie to add- $value
string
$value Value to set
Returns
Implementation of
Remove a specific cookie value by name
Parameters
- $name
string
$name Cookie to remove by name
Returns
Implementation of
public
Guzzle\Http\Message\Request
setEventDispatcher( Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher )
Set the EventDispatcher of the request
Parameters
- $eventDispatcher
Symfony\Component\EventDispatcher\EventDispatcherInterface
$eventDispatcher
Returns
Implementation of
Get the EventDispatcher of the request
Returns
Symfony\Component\EventDispatcher\EventDispatcherInterfaceImplementation of
Helper to dispatch Guzzle events and set the event name on the event
Parameters
- $eventName
string
$eventName Name of the event to dispatch- $context
array
$context Context of the event
Returns
Implementation of
public
Guzzle\Http\Message\Request
addSubscriber( Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber )
Add an event subscriber to the dispatcher
Parameters
- $subscriber
Symfony\Component\EventDispatcher\EventSubscriberInterface
$subscriber Event subscriber
Returns
Implementation of
Get an array containing the request and response for event notifications
Returns
arrayProcess a received response
Parameters
- $context
array
$context Contextual information
Throws
Guzzle\Http\Exception\RequestException|Guzzle\Http\Exception\BadResponseExceptionon unsuccessful responses
Methods inherited from Guzzle\Http\Message\AbstractMessage
addHeader(),
addHeaders(),
getHeader(),
getHeaderLines(),
getHeaders(),
getParams(),
hasHeader(),
removeHeader(),
setHeader(),
setHeaderFactory(),
setHeaders()
Magic methods summary
Constants summary
Constants inherited from Guzzle\Http\Message\RequestInterface
CONNECT,
DELETE,
GET,
HEAD,
OPTIONS,
PATCH,
POST,
PUT,
STATE_COMPLETE,
STATE_ERROR,
STATE_NEW,
STATE_TRANSFER,
TRACE
Properties summary
protected
Symfony\Component\EventDispatcher\EventDispatcherInterface
|
$eventDispatcher | |
protected
|
$url |
#
HTTP Url |
protected
string
|
$method |
#
HTTP method (GET, PUT, POST, DELETE, HEAD, OPTIONS, TRACE) |
protected
|
$client | |
protected
|
$response |
#
Response of the request |
protected
|
$responseBody |
#
Response body |
protected
string
|
$state |
#
State of the request object |
protected
string
|
$username |
#
Authentication username |
protected
string
|
$password |
#
Auth password |
protected
|
$curlOptions |
#
cURL specific transfer options |
protected
boolean
|
$isRedirect |
Properties inherited from Guzzle\Http\Message\AbstractMessage
$headerFactory,
$headers,
$params,
$protocol,
$protocolVersion