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)
todo | Implement proxy settings |
---|---|
category | Zend |
package | Zend_Http |
subpackage | Client |
\Zend_Http_Client_Exception |
|
copyright | Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
license | New BSD License |
__construct(\Zend_Uri_Http|string $uri= null
, array $config= null
)
\Zend_Uri_Http
string
array
Configuration key-value pairs.
encodeAuthHeader(string $user, string $password, string $type = self::AUTH_BASIC
) : string
encodeFormData(string $boundary, string $name, mixed $value, string $filename= null
, array $headers= array()
) : string
string
string
mixed
string
array
Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary")
string
getAdapter() : \Zend_Http_Client_Adapter_Interface
\Zend_Http_Client_Adapter_Interface
$adaptergetCookieJar() : \Zend_Http_CookieJar | null
\Zend_Http_CookieJar
null
getHeader(string $key) : string | array | null
Note that if the header has more than one value, an array will be returned.
string
string
array
null
The header value or null if it is not setgetLastRequest() : string
string
getLastResponse() : \Zend_Http_Response
If $config['storeresponse'] is set to false, or no response was stored yet, will return null
\Zend_Http_Response
or null if nonegetRedirectionsCount() : integer
integer
getStream() : boolean | string
boolean
string
getUnmaskStatus() : boolean
boolean
getUri(boolean $as_string = false
) : \Zend_Uri_Http | string
boolean
If true, will return the URI as a string
\Zend_Uri_Http
string
request(string $method = null
) : \Zend_Http_Response
string
\Zend_Http_Client_Exception |
---|
\Zend_Http_Response
resetParameters(boolean $clearAll = false
) : \Zend_Http_Client
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_*
boolean
Should all data be cleared?
\Zend_Http_Client
setAdapter(\Zend_Http_Client_Adapter_Interface|string $adapter) : null
While this method is not called more than one for a client, it is seperated from ->request() to preserve logic and readability
\Zend_Http_Client_Adapter_Interface
string
\Zend_Http_Client_Exception |
---|
null
setAuth(string|false $user, string $password= ''
, string $type= self::AUTH_BASIC
) : \Zend_Http_Client
$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);
see |
---|
string
false
User name or false disable authentication
string
Password
string
Authentication type
\Zend_Http_Client_Exception |
---|
\Zend_Http_Client
setConfig($config = array()
) : \Zend_Http_Client
\Zend_Http_Client_Exception |
---|
\Zend_Http_Client
setCookie(\Zend_Http_Cookie|string $cookie, string|null $value = null
) : \Zend_Http_Client
\Zend_Http_Cookie
string
string
null
If "cookie" is a string, this is the cookie value.
\Zend_Http_Client_Exception |
---|
\Zend_Http_Client
setCookieJar(\Zend_Http_CookieJar|boolean $cookiejar = true
) : \Zend_Http_Client
A cookie jar is an object that holds and maintains cookies across HTTP requests and responses.
\Zend_Http_CookieJar
boolean
Existing cookiejar object, true to create a new one, false to disable
\Zend_Http_Client_Exception |
---|
\Zend_Http_Client
setEncType(string $enctype = self::ENC_URLENCODED
) : \Zend_Http_Client
string
\Zend_Http_Client
setFileUpload(string $filename, string $formname, string $data= null
, string $ctype= null
) : \Zend_Http_Client
Can be used in two ways:
string
Name of file to upload, or name to save as
string
Name of form element to send as
string
Data to send (if null, $filename is read and sent)
string
Content type to use (if $data is set and $ctype is null, will be application/octet-stream)
\Zend_Http_Client_Exception |
---|
\Zend_Http_Client
setHeaders(string|array $name, mixed $value = null
) : \Zend_Http_Client
This function can be used in several ways to set the client's request headers:
string
array
Header name, full header string ('Header: value') or an array of headers
mixed
Header value or null
\Zend_Http_Client_Exception |
---|
\Zend_Http_Client
setMethod(string $method = self::GET
) : \Zend_Http_Client
Validated the passed method and sets it. If we have files set for POST requests, and the new method is not POST, the files are silently dropped.
string
\Zend_Http_Client_Exception |
---|
\Zend_Http_Client
setParameterGet(string|array $name, string $value = null
) : \Zend_Http_Client
string
array
string
\Zend_Http_Client
setParameterPost(string|array $name, string $value = null
) : \Zend_Http_Client
string
array
string
\Zend_Http_Client
setRawData(string|resource $data, string $enctype = null
) : \Zend_Http_Client
This function is here for two reasons:
$data can also be stream (such as file) from which the data will be read.
string
resource
string
\Zend_Http_Client
setStream(string|boolean $streamfile = true
) : \Zend_Http_Client
string
boolean
Stream file, true for temp file, false/null for no streaming
\Zend_Http_Client
setUnmaskStatus(boolean $status = true
) : \Zend_Http_Client
Example: foo%5B0%5D=a&foo%5B1%5D=b becomes foo=a&foo=b
This is usefull for some services
boolean
\Zend_Http_Client
setUri(\Zend_Uri_Http|string $uri) : \Zend_Http_Client
\Zend_Uri_Http
string
\Zend_Http_Client_Exception |
---|
\Zend_Http_Client
_detectFileMimeType(string $file) : string
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
string
File path
string
MIME type_flattenParametersArray(array $parray, string $prefix = null
) : array
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.
since | 1.9 |
---|
array
string
array
_getParametersRecursive(array $parray, boolean $urlencode = false
) : array
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
deprecated | since 1.9 |
---|
array
The parameters array
boolean
Whether to urlencode the name and value
array
_openTempStream() : resource
resource
_prepareBody() : string
\Zend_Http_Client_Exception |
---|
string
_prepareHeaders() : array
array
_setParameter(string $type, string $name, string $value) : null
string
GET or POST
string
string
null
_validateHeaderValue(string|object|array $value, boolean $recurse = true
)
$_fileInfoDb : resource
null
This variable is populated the first time _detectFileMimeType is called and is then reused on every call to this method
$_queryBracketsEscaped : boolean
true
$_unmaskStatus : boolean
false
$adapter : \Zend_Http_Client_Adapter_Interface
null
$auth : array | null
Expected to be an associative array with this structure: $this->auth = array('user' => 'username', 'password' => 'password', 'type' => 'basic') Where 'type' should be one of the supported authentication types (see the AUTH_* constants), for example 'basic' or 'digest'.
If null, no authentication will be used.
$body_field_order : array
array()
An associative array, where each element is of the format:
'
$config : array
array('maxredirects' => 5, 'strictredirects' => false, 'useragent' => 'Zend_Http_Client', 'timeout' => 10, 'adapter' => 'Zend_Http_Client_Adapter_Socket', 'httpversion' => self::HTTP_1, 'keepalive' => false, 'storeresponse' => true, 'strict' => true, 'output_stream' => false, 'encodecookies' => true, 'rfc3986_strict' => false)
$enctype : string
null
$files : array
array()
An associative array, where each element is of the format: 'name' => array('filename.txt', 'text/plain', 'This is the actual file contents')
$headers : array
array()
$last_request : string
null
$last_response : \Zend_Http_Response
null
$method : string
self::GET
$paramsGet : array
array()
$paramsPost : array
array()
$raw_post_data : string
null
$redirectCounter : integer
0
$uri : \Zend_Uri_Http
null
AUTH_BASIC = 'basic'
CONNECT = 'CONNECT'
CONTENT_LENGTH = 'Content-Length'
CONTENT_TYPE = 'Content-Type'
DELETE = 'DELETE'
ENC_FORMDATA = 'multipart/form-data'
ENC_URLENCODED = 'application/x-www-form-urlencoded'
GET = 'GET'
HEAD = 'HEAD'
HTTP_0 = '1.0'
HTTP_1 = '1.1'
MERGE = 'MERGE'
OPTIONS = 'OPTIONS'
PATCH = 'PATCH'
POST = 'POST'
PUT = 'PUT'
TRACE = 'TRACE'
VTYPE_FILE = 'FILE'
VTYPE_SCALAR = 'SCALAR'