Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
Zend_Http_Client is an implementation of an HTTP client in PHP. The client supports basic features like sending different HTTP requests and handling redirections, as well as more advanced features like proxy settings, HTTP authentication and cookie persistence (using a Zend_Http_CookieJar object)

\Zend_Oauth_Config
$_config= 'null'
Holds the current OAuth Configuration set encapsulated in an instance of Zend_Oauth_Config; it's not a Zend_Config instance since that level of abstraction is unnecessary and doesn't let me escape the accessors and mutators anyway!

bool
$_streamingRequest= 'null'
True if this request is being made with data supplied by a stream object instead of a raw encoded string.
null
Details
__call(
string $method, array $args
)
:
mixed
Simple Proxy to the current Zend_Oauth_Config method. It's that instance which holds all configuration methods and values this object also presents as it's API.
Name | Type | Description |
---|---|---|
$method | string | |
$args | array |
Type | Description |
---|---|
mixed |
Exception | Description |
---|---|
\Zend_Oauth_Exception | if method does not exist in config object |

__construct(
array|\Zend_Config $oauthOptions, string $uri
=
null, array|\Zend_Config $config
=
null
)
:
void
Constructor; creates a new HTTP Client instance which itself is just a typical Zend_Http_Client subclass with some OAuth icing to assist in automating OAuth parameter generation, addition and cryptographioc signing of requests.
Name | Type | Description |
---|---|---|
$oauthOptions | array|\Zend_Config | |
$uri | string | |
$config | array|\Zend_Config |

_detectFileMimeType(
string $file
)
:
string
Attempt to detect the MIME type of a file using available extensions
Inherited from: \Zend_Http_Client::_detectFileMimeType()This method will try to detect the MIME type of a file. If the fileinfo extension is available, it will be used. If not, the mime_magic extension which is deprected but is still available in many PHP setups will be tried.
If neither extension is available, the default application/octet-stream MIME type will be returned
Name | Type | Description |
---|---|---|
$file | string | File path |
Type | Description |
---|---|
string | MIME type |

_flattenParametersArray(
array $parray, string $prefix
=
null
)
:
array
Convert an array of parameters into a flat array of (key, value) pairs
Inherited from: \Zend_Http_Client::_flattenParametersArray()Will flatten a potentially multi-dimentional array of parameters (such as POST parameters) into a flat array of (key, value) paris. In case of multi-dimentional arrays, square brackets ([]) will be added to the key to indicate an array.
Name | Type | Description |
---|---|---|
$parray | array | |
$prefix | string |
Type | Description |
---|---|
array |

_getParametersRecursive(
array $parray, bool $urlencode
=
false
)
:
array
Helper method that gets a possibly multi-level parameters array (get or post) and flattens it.
Inherited from: \Zend_Http_Client::_getParametersRecursive()The method returns an array of (key, value) pairs (because keys are not necessarily unique. If one of the parameters in as array, it will also add a [] suffix to the key.
This method is deprecated since Zend Framework 1.9 in favour of self::_flattenParametersArray() and will be dropped in 2.0
Name | Type | Description |
---|---|---|
$parray | array | The parameters array |
$urlencode | bool | Whether to urlencode the name and value |
Type | Description |
---|---|
array |

_getSignableParametersAsQueryString(
)
:
string
Collect all signable parameters into a single array across query string and POST body. These are returned as a properly formatted single query string.
Type | Description |
---|---|
string |

_openTempStream(
)
:
resource
Create temporary stream
Inherited from: \Zend_Http_Client::_openTempStream()Type | Description |
---|---|
resource |

_prepareHeaders(
)
:
array
Prepare the request headers
Inherited from: \Zend_Http_Client::_prepareHeaders()Type | Description |
---|---|
array |

_setParameter(
string $type, string $name, string $value
)
:
null
Set a GET or POST parameter - used by SetParameterGet and SetParameterPost
Inherited from: \Zend_Http_Client::_setParameter()Name | Type | Description |
---|---|---|
$type | string | GET or POST |
$name | string | |
$value | string |
Type | Description |
---|---|
null |

encodeAuthHeader(
string $user, string $password, string $type
=
self
)
:
string
Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.
Inherited from: \Zend_Http_Client::encodeAuthHeader()Name | Type | Description |
---|---|---|
$user | string | |
$password | string | |
$type | string |
Type | Description |
---|---|
string |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

encodeFormData(
string $boundary, string $name, mixed $value, string $filename
=
null, array $headers
=
array
)
:
string
Encode data to a multipart/form-data part suitable for a POST request.
Inherited from: \Zend_Http_Client::encodeFormData()Name | Type | Description |
---|---|---|
$boundary | string | |
$name | string | |
$value | mixed | |
$filename | string | |
$headers | array | Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary") |
Type | Description |
---|---|
string |

getAdapter(
)
:
\Zend_Http_Client_Adapter_Interface
Load the connection adapter
Inherited from: \Zend_Http_Client::getAdapter()Type | Description |
---|---|
\Zend_Http_Client_Adapter_Interface | $adapter |

getCookieJar(
)
:
\Zend_Http_CookieJar|null
Return the current cookie jar or null if none.
Inherited from: \Zend_Http_Client::getCookieJar()Type | Description |
---|---|
\Zend_Http_CookieJarnull |

getHeader(
string $key
)
:
string|array|null
Get the value of a specific header
Inherited from: \Zend_Http_Client::getHeader()Note that if the header has more than one value, an array will be returned.
Name | Type | Description |
---|---|---|
$key | string |
Type | Description |
---|---|
stringarraynull | The header value or null if it is not set |

getLastRequest(
)
:
string
Get the last HTTP request as string
Inherited from: \Zend_Http_Client::getLastRequest()Type | Description |
---|---|
string |

getLastResponse(
)
:
\Zend_Http_Response
Get the last HTTP response received by this client
Inherited from: \Zend_Http_Client::getLastResponse()If $config['storeresponse'] is set to false, or no response was stored yet, will return null
Type | Description |
---|---|
\Zend_Http_Response | or null if none |

getRedirectionsCount(
)
:
int
Get the number of redirections done on the last request
Inherited from: \Zend_Http_Client::getRedirectionsCount()Type | Description |
---|---|
int |

getStream(
)
:
boolean|string
Get status of streaming for received data
Inherited from: \Zend_Http_Client::getStream()Type | Description |
---|---|
booleanstring |

getStreamingRequest(
)
:
boolean
Check whether the client is set to perform streaming requests.
Type | Description |
---|---|
boolean | True if yes, false otherwise. |

getUnmaskStatus(
)
:
boolean
Returns the currently configured unmask status
Inherited from: \Zend_Http_Client::getUnmaskStatus()Type | Description |
---|---|
boolean |

getUri(
boolean $as_string
=
false
)
:
\Zend_Uri_Http|string
Get the URI for the next request
Inherited from: \Zend_Http_Client::getUri()Name | Type | Description |
---|---|---|
$as_string | boolean | If true, will return the URI as a string |
Type | Description |
---|---|
\Zend_Uri_Httpstring |

prepareOauth(
)
:
void
Performs OAuth preparation on the request before sending.
This primarily means taking a request, correctly encoding and signing all parameters, and applying the correct OAuth scheme to the method being used.
Exception | Description |
---|---|
\Zend_Oauth_Exception | If POSTBODY scheme requested, but GET request method used; or if invalid request scheme provided |

request(
string $method
=
null
)
:
\Zend_Http_Response
Same as Zend_Http_Client::request() except just before the request is executed, we automatically append any necessary OAuth parameters and sign the request using the relevant signature method.
Name | Type | Description |
---|---|---|
$method | string |
Type | Description |
---|---|
\Zend_Http_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

resetParameters(
bool $clearAll
=
false
)
:
\Zend_Http_Client
Clear all custom parameters we set.
Should be used to reset the request parameters if the client is used for several concurrent requests.
clearAll parameter controls if we clean just parameters or also headers and last_*
Name | Type | Description |
---|---|---|
$clearAll | bool | Should all data be cleared? |
Type | Description |
---|---|
\Zend_Http_Client |

setAdapter(
\Zend_Http_Client_Adapter_Interface $adapter
)
:
void
Load the connection adapter
While this method is not called more than one for a client, it is seperated from ->request() to preserve logic and readability
Name | Type | Description |
---|---|---|
$adapter | \Zend_Http_Client_Adapter_Interface |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

setAuth(
string|false $user, string $password, string $type
=
self
)
:
\Zend_Http_Client
Set HTTP authentication parameters
Inherited from: \Zend_Http_Client::setAuth()$type should be one of the supported types - see the self::AUTH_* constants.
To enable authentication:
$this->setAuth('shahar', 'secret', Zend_Http_Client::AUTH_BASIC);
To disable authentication:
$this->setAuth(false);
Name | Type | Description |
---|---|---|
$user | string|false | User name or false disable authentication |
$password | string | Password |
$type | string | Authentication type |
Type | Description |
---|---|
\Zend_Http_Client |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

setConfig(
\Zend_Config $config
=
array
)
:
\Zend_Http_Client
Set configuration parameters for this HTTP client
Inherited from: \Zend_Http_Client::setConfig()Name | Type | Description |
---|---|---|
$config | \Zend_Config | | array $config |
Type | Description |
---|---|
\Zend_Http_Client |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

setCookie(
\Zend_Http_Cookie|string $cookie, string|null $value
=
null
)
:
\Zend_Http_Client
Add a cookie to the request. If the client has no Cookie Jar, the cookies will be added directly to the headers array as "Cookie" headers.
Inherited from: \Zend_Http_Client::setCookie()Name | Type | Description |
---|---|---|
$cookie | \Zend_Http_Cookie|string | |
$value | string|null | If "cookie" is a string, this is the cookie value. |
Type | Description |
---|---|
\Zend_Http_Client |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

setCookieJar(
\Zend_Http_CookieJar|boolean $cookiejar
=
true
)
:
\Zend_Http_Client
Set the HTTP client's cookie jar.
Inherited from: \Zend_Http_Client::setCookieJar()A cookie jar is an object that holds and maintains cookies across HTTP requests and responses.
Name | Type | Description |
---|---|---|
$cookiejar | \Zend_Http_CookieJar|boolean | Existing cookiejar object, true to create a new one, false to disable |
Type | Description |
---|---|
\Zend_Http_Client |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

setEncType(
string $enctype
=
self
)
:
\Zend_Http_Client
Set the encoding type for POST data
Inherited from: \Zend_Http_Client::setEncType()
setFileUpload(
string $filename, string $formname, string $data
=
null, string $ctype
=
null
)
:
\Zend_Http_Client
Set a file to upload (using a POST request)
Inherited from: \Zend_Http_Client::setFileUpload()Can be used in two ways:
Name | Type | Description |
---|---|---|
$filename | string | Name of file to upload, or name to save as |
$formname | string | Name of form element to send as |
$data | string | Data to send (if null, $filename is read and sent) |
$ctype | string | Content type to use (if $data is set and $ctype is null, will be application/octet-stream) |
Type | Description |
---|---|
\Zend_Http_Client |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

setHeaders(
string|array $name, mixed $value
=
null
)
:
\Zend_Http_Client
Set one or more request headers
Inherited from: \Zend_Http_Client::setHeaders()This function can be used in several ways to set the client's request headers: 1. By providing two parameters: $name as the header to set (e.g. 'Host') and $value as it's value (e.g. 'www.example.com'). 2. By providing a single header string as the only parameter e.g. 'Host: www.example.com' 3. By providing an array of headers as the first parameter e.g. array('host' => 'www.example.com', 'x-foo: bar'). In This case the function will call itself recursively for each array item.
Name | Type | Description |
---|---|---|
$name | string|array | Header name, full header string ('Header: value') or an array of headers |
$value | mixed | Header value or null |
Type | Description |
---|---|
\Zend_Http_Client |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

setMethod(
string $method
=
self
)
:
\Zend_Http_Client
Same as Zend_Http_Client::setMethod() except it also creates an Oauth specific reference to the method type.
Might be defunct and removed in a later iteration.
Name | Type | Description |
---|---|---|
$method | string |
Type | Description |
---|---|
\Zend_Http_Client |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |

setParameterGet(
string|array $name, string $value
=
null
)
:
\Zend_Http_Client
Set a GET parameter for the request. Wrapper around _setParameter
Inherited from: \Zend_Http_Client::setParameterGet()Name | Type | Description |
---|---|---|
$name | string|array | |
$value | string |
Type | Description |
---|---|
\Zend_Http_Client |

setParameterPost(
string|array $name, string $value
=
null
)
:
\Zend_Http_Client
Set a POST parameter for the request. Wrapper around _setParameter
Inherited from: \Zend_Http_Client::setParameterPost()Name | Type | Description |
---|---|---|
$name | string|array | |
$value | string |
Type | Description |
---|---|
\Zend_Http_Client |

setRawData(
string|resource $data, string $enctype
=
null
)
:
\Zend_Http_Client
Set the raw (already encoded) POST data.
Inherited from: \Zend_Http_Client::setRawData()This function is here for two reasons: 1. For advanced user who would like to set their own data, already encoded 2. For backwards compatibilty: If someone uses the old post($data) method. this method will be used to set the encoded data.
$data can also be stream (such as file) from which the data will be read.
Name | Type | Description |
---|---|---|
$data | string|resource | |
$enctype | string |
Type | Description |
---|---|
\Zend_Http_Client |

setRawDataStream(
string $data, string $enctype
=
null
)
:
\Zend_Http_Client
Set the raw (already encoded) POST data from a stream source.
This is used to support POSTing from open file handles without caching the entire body into memory. It is a wrapper around Zend_Http_Client::setRawData().
Name | Type | Description |
---|---|---|
$data | string | The request data |
$enctype | string | The encoding type |
Type | Description |
---|---|
\Zend_Http_Client |

setStream(
string|boolean $streamfile
=
true
)
:
\Zend_Http_Client
Set streaming for received data
Inherited from: \Zend_Http_Client::setStream()Name | Type | Description |
---|---|---|
$streamfile | string|boolean | Stream file, true for temp file, false/null for no streaming |
Type | Description |
---|---|
\Zend_Http_Client |

setStreamingRequest(
boolean $value
)
:
void
Set the streamingRequest variable which controls whether we are sending the raw (already encoded) POST data from a stream source.
Name | Type | Description |
---|---|---|
$value | boolean | The value to set. |

setUnmaskStatus(
boolean $status
=
true
)
:
\Zend_Http_Client
Set the unmask feature for GET parameters as array
Inherited from: \Zend_Http_Client::setUnmaskStatus()Example: foo%5B0%5D=a&foo%5B1%5D=b becomes foo=a&foo=b
This is usefull for some services
Name | Type | Description |
---|---|---|
$status | boolean |
Type | Description |
---|---|
\Zend_Http_Client |

setUri(
\Zend_Uri_Http|string $uri
)
:
\Zend_Http_Client
Set the URI for the next request
Inherited from: \Zend_Http_Client::setUri()Name | Type | Description |
---|---|---|
$uri | \Zend_Uri_Http|string |
Type | Description |
---|---|
\Zend_Http_Client |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |