Class Response
Guzzle HTTP response object
- Guzzle\Http\Message\AbstractMessage implements Guzzle\Http\Message\MessageInterface
-
Guzzle\Http\Message\Response
implements
Serializable
Methods summary
-
public staticfromMessage ( string $message )Create a new Response based on a raw response message
-
public__construct ( string $statusCode, ToArrayInterface|array $headers = null, string|resource|EntityBodyInterface $body = null )Construct the response
-
public__toString ( ) -
publicserialize ( ) -
publicunserialize ( mixed $serialize ) -
publicgetBody ( bool $asString = false )Get the response entity body
-
publicsetBody ( EntityBodyInterface|string $body )Set the response entity body
-
publicsetProtocol ( string $protocol, string $version )Set the protocol and protocol version of the response
-
publicgetProtocol ( )Get the protocol used for the response (e.g. HTTP)
-
publicgetProtocolVersion ( )Get the HTTP protocol version
-
publicgetInfo ( string $key = null )Get a cURL transfer information
-
publicsetInfo ( array $info )Set the transfer information
-
publicsetStatus ( int $statusCode, string $reasonPhrase = '' )Set the response status
-
publicgetStatusCode ( )Get the response status code
-
publicgetMessage ( )Get the entire response as a string
-
publicgetRawHeaders ( )Get the the raw message headers as a string
-
publicgetReasonPhrase ( )Get the response reason phrase- a human readable version of the numeric status code
-
publicgetAcceptRanges ( )Get the Accept-Ranges HTTP header
-
publiccalculateAge ( )Calculate the age of the response
-
publicgetAge ( )Get the Age HTTP header
-
publicgetAllow ( )Get the Allow HTTP header
-
publicisMethodAllowed ( string $method )Check if an HTTP method is allowed by checking the Allow response header
-
publicgetCacheControl ( )Get the Cache-Control HTTP header
-
publicgetConnection ( )Get the Connection HTTP header
-
publicgetContentEncoding ( )Get the Content-Encoding HTTP header
-
publicgetContentLanguage ( )Get the Content-Language HTTP header
-
publicgetContentLength ( )Get the Content-Length HTTP header
-
publicgetContentLocation ( )Get the Content-Location HTTP header
-
publicgetContentDisposition ( )Get the Content-Disposition HTTP header
-
publicgetContentMd5 ( )Get the Content-MD5 HTTP header
-
publicgetContentRange ( )Get the Content-Range HTTP header
-
publicgetContentType ( )Get the Content-Type HTTP header
-
publicisContentType ( string $type )Checks if the Content-Type is of a certain type. This is useful if the Content-Type header contains charset information and you need to know if the Content-Type matches a particular type.
-
publicgetDate ( )Get the Date HTTP header
-
publicgetEtag ( )Get the ETag HTTP header
-
publicgetExpires ( )Get the Expires HTTP header
-
publicgetLastModified ( )Get the Last-Modified HTTP header
-
publicgetLocation ( )Get the Location HTTP header
-
publicgetPragma ( )Get the Pragma HTTP header
-
publicgetProxyAuthenticate ( )Get the Proxy-Authenticate HTTP header
-
publicgetRetryAfter ( )Get the Retry-After HTTP header
-
publicgetServer ( )Get the Server HTTP header
-
publicgetSetCookie ( )Get the Set-Cookie HTTP header
-
publicgetTrailer ( )Get the Trailer HTTP header
-
publicgetTransferEncoding ( )Get the Transfer-Encoding HTTP header
-
publicgetVary ( )Get the Vary HTTP header
-
publicgetVia ( )Get the Via HTTP header
-
publicgetWarning ( )Get the Warning HTTP header
-
publicgetWwwAuthenticate ( )Get the WWW-Authenticate HTTP header
-
publicisClientError ( )Checks if HTTP Status code is a Client Error (4xx)
-
publicisError ( )Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)
-
publicisInformational ( )Checks if HTTP Status code is Information (1xx)
-
publicisRedirect ( )Checks if HTTP Status code is a Redirect (3xx)
-
publicisServerError ( )Checks if HTTP Status code is Server Error (5xx)
-
publicisSuccessful ( )Checks if HTTP Status code is Successful (2xx | 304)
-
publiccanCache ( )Check if the response can be cached based on the response headers
-
publicgetMaxAge ( )Gets the number of seconds from the current time in which this response is still considered fresh
-
publicisFresh ( )Check if the response is considered fresh.
-
publiccanValidate ( )Check if the response can be validated against the origin server using a conditional GET request.
-
publicgetFreshness ( )Get the freshness of the response by returning the difference of the maximum lifetime of the response and the age of the response (max-age - age).
-
publicjson ( )Parse the JSON response body and return an array
-
publicxml ( )Parse the XML response body and return a \SimpleXMLElement.
-
publicgetRedirectCount ( )Get the redirect count of this response
-
publicsetEffectiveUrl ( string $url )Set the effective URL that resulted in this response (e.g. the last redirect URL)
-
publicgetEffectiveUrl ( )Get the effective URL that resulted in this response (e.g. the last redirect URL)
Methods detail
Create a new Response based on a raw response message
Parameters
- $message
string
$message Response message
Returns
public
__construct( string $statusCode, Guzzle\Common\ToArrayInterface|array $headers = null, string|resource|Guzzle\Http\EntityBodyInterface $body = null )
Construct the response
Parameters
- $statusCode
string
$statusCode The response status code (e.g. 200, 404, etc)- $headers
Guzzle\Common\ToArrayInterface|array
$headers The response headers- $body
string|resource|Guzzle\Http\EntityBodyInterface
$body The body of the response
Throws
Overrides
Returns
stringImplementation of
Implementation of
Get the response entity body
Parameters
- $asString
boolean
$asString Set to TRUE to return a string of the body rather than a full body object
Returns
Set the response entity body
Parameters
- $body
Guzzle\Http\EntityBodyInterface|string
$body Body to set
Returns
Set the protocol and protocol version of the response
Parameters
- $protocol
string
$protocol Response protocol- $version
string
$version Protocol version
Returns
Get the protocol used for the response (e.g. HTTP)
Returns
stringGet the HTTP protocol version
Returns
stringGet a cURL transfer information
Parameters
- $key
string
$key A single statistic to check
Returns
array|string|nullReturns all stats if no key is set, a single stat if a key is set, or null if a key is set and not found
Link
Set the transfer information
Parameters
- $info
array
$info Array of cURL transfer stats
Returns
Set the response status
Parameters
- $statusCode
integer
$statusCode Response status code to set- $reasonPhrase
string
$reasonPhrase Response reason phrase
Returns
Throws
Get the response status code
Returns
integerGet the entire response as a string
Returns
stringGet the the raw message headers as a string
Returns
stringGet the response reason phrase- a human readable version of the numeric status code
Returns
stringGet the Accept-Ranges HTTP header
Returns
stringReturns what partial content range types this server supports.
Calculate the age of the response
Returns
integerGet the Age HTTP header
Returns
integer|nullReturns the age the object has been in a proxy cache in seconds.
Get the Allow HTTP header
Returns
string|nullReturns valid actions for a specified resource. To be used for a 405 Method not allowed.
Check if an HTTP method is allowed by checking the Allow response header
Parameters
- $method
string
$method Method to check
Returns
booleanGet the Cache-Control HTTP header
Returns
stringGet the Connection HTTP header
Returns
stringGet the Content-Encoding HTTP header
Returns
string|nullGet the Content-Language HTTP header
Returns
string|nullReturns the language the content is in.
Get the Content-Length HTTP header
Returns
integerReturns the length of the response body in bytes
Get the Content-Location HTTP header
Returns
string|nullReturns an alternate location for the returned data (e.g /index.htm)
Get the Content-Disposition HTTP header
Returns
string|nullReturns the Content-Disposition header
Get the Content-MD5 HTTP header
Returns
string|nullReturns a Base64-encoded binary MD5 sum of the content of the response.
Get the Content-Range HTTP header
Returns
stringReturns where in a full body message this partial message belongs (e.g. bytes 21010-47021/47022).
Get the Content-Type HTTP header
Returns
stringReturns the mime type of this content.
Checks if the Content-Type is of a certain type. This is useful if the Content-Type header contains charset information and you need to know if the Content-Type matches a particular type.
Parameters
- $type
string
$type Content type to check against
Returns
booleanGet the Date HTTP header
Returns
string|nullReturns the date and time that the message was sent.
Get the ETag HTTP header
Returns
string|nullReturns an identifier for a specific version of a resource, often a Message digest.
Get the Expires HTTP header
Returns
string|nullReturns the date/time after which the response is considered stale.
Get the Last-Modified HTTP header
Returns
string|nullReturns the last modified date for the requested object, in RFC 2822 format (e.g. Tue, 15 Nov 1994 12:45:26 GMT)
Get the Location HTTP header
Returns
string|nullUsed in redirection, or when a new resource has been created.
Get the Pragma HTTP header
Returns
Guzzle\Http\Message\Header|nullReturns the implementation-specific headers that may have various effects anywhere along the request-response chain.
Get the Proxy-Authenticate HTTP header
Returns
string|nullAuthentication to access the proxy (e.g. Basic)
Get the Retry-After HTTP header
Returns
integer|nullIf an entity is temporarily unavailable, this instructs the client to try again after a specified period of time.
Get the Server HTTP header
Returns
string|nullA name for the server
Get the Set-Cookie HTTP header
Returns
string|nullAn HTTP cookie.
Get the Trailer HTTP header
Returns
string|nullThe Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding.
Get the Transfer-Encoding HTTP header
Returns
string|nullThe form of encoding used to safely transfer the entity to the user
Get the Vary HTTP header
Returns
string|nullTells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server.
Get the Via HTTP header
Returns
string|nullInforms the client of proxies through which the response was sent.
Get the Warning HTTP header
Returns
string|nullA general warning about possible problems with the entity body
Get the WWW-Authenticate HTTP header
Returns
string|nullIndicates the authentication scheme that should be used to access the requested entity
Checks if HTTP Status code is a Client Error (4xx)
Returns
booleanChecks if HTTP Status code is Server OR Client Error (4xx or 5xx)
Returns
booleanChecks if HTTP Status code is Information (1xx)
Returns
booleanChecks if HTTP Status code is a Redirect (3xx)
Returns
booleanChecks if HTTP Status code is Server Error (5xx)
Returns
booleanChecks if HTTP Status code is Successful (2xx | 304)
Returns
booleanCheck if the response can be cached based on the response headers
Returns
booleanReturns TRUE if the response can be cached or false if not
Gets the number of seconds from the current time in which this response is still considered fresh
Returns
integer|nullReturns the number of seconds
Check if the response is considered fresh.
A response is considered fresh when its age is less than or equal to the freshness lifetime (maximum age) of the response.
Returns
boolean|nullCheck if the response can be validated against the origin server using a conditional GET request.
Returns
booleanGet the freshness of the response by returning the difference of the maximum lifetime of the response and the age of the response (max-age - age).
Freshness values less than 0 mean that the response is no longer fresh and is ABS(freshness) seconds expired. Freshness values of greater than zero is the number of seconds until the response is no longer fresh. A NULL result means that no freshness information is available.
Returns
integerParse the JSON response body and return an array
Returns
array|string|integer|boolean|floatThrows
Parse the XML response body and return a \SimpleXMLElement.
In order to prevent XXE attacks, this method disables loading external entities. If you rely on external entities, then you must parse the XML response manually by accessing the response body directly.
Returns
Throws
Link
Get the redirect count of this response
Returns
integerSet the effective URL that resulted in this response (e.g. the last redirect URL)
Parameters
- $url
string
$url The effective URL
Returns
Get the effective URL that resulted in this response (e.g. the last redirect URL)
Returns
stringMethods inherited from Guzzle\Http\Message\AbstractMessage
addHeader(),
addHeaders(),
getHeader(),
getHeaderLines(),
getHeaders(),
getParams(),
hasHeader(),
removeHeader(),
setHeader(),
setHeaderFactory(),
setHeaders()
Magic methods summary
Properties summary
protected
|
$body |
#
The response body |
protected
string
|
$reasonPhrase |
#
The reason phrase of the response (human readable code) |
protected
string
|
$statusCode |
#
The status code of the response |
protected
array
|
$info |
#
Information about the request |
protected
string
|
$effectiveUrl |
#
The effective URL that returned this response |
protected static
array
|
$cacheResponseCodes |
#
Cacheable response codes (see RFC 2616:13.4) |
Properties inherited from Guzzle\Http\Message\AbstractMessage
$headerFactory,
$headers,
$params,
$protocol,
$protocolVersion