Zend Framework
1.12
|
Public Member Functions | |
__construct ($uri=null, $config=null) | |
Constructor method. | |
setUri ($uri) | |
Set the URI for the next request. | |
getUri ($as_string=false) | |
Get the URI for the next request. | |
setConfig ($config=array()) | |
Set configuration parameters for this HTTP client. | |
setMethod ($method=self::GET) | |
Set the next request's method. | |
setHeaders ($name, $value=null) | |
Set one or more request headers. | |
getHeader ($key) | |
Get the value of a specific header. | |
setParameterGet ($name, $value=null) | |
Set a GET parameter for the request. | |
setParameterPost ($name, $value=null) | |
Set a POST parameter for the request. | |
getRedirectionsCount () | |
Get the number of redirections done on the last request. | |
setAuth ($user, $password= '', $type=self::AUTH_BASIC) | |
Set HTTP authentication parameters. | |
setCookieJar ($cookiejar=true) | |
Set the HTTP client's cookie jar. | |
getCookieJar () | |
Return the current cookie jar or null if none. | |
setCookie ($cookie, $value=null) | |
Add a cookie to the request. | |
setFileUpload ($filename, $formname, $data=null, $ctype=null) | |
Set a file to upload (using a POST request) | |
setEncType ($enctype=self::ENC_URLENCODED) | |
Set the encoding type for POST data. | |
setRawData ($data, $enctype=null) | |
Set the raw (already encoded) POST data. | |
setUnmaskStatus ($status=true) | |
Set the unmask feature for GET parameters as array. | |
getUnmaskStatus () | |
Returns the currently configured unmask status. | |
resetParameters ($clearAll=false) | |
Clear all GET and POST parameters. | |
getLastRequest () | |
Get the last HTTP request as string. | |
getLastResponse () | |
Get the last HTTP response received by this client. | |
setAdapter ($adapter) | |
Load the connection adapter. | |
getAdapter () | |
Load the connection adapter. | |
setStream ($streamfile=true) | |
Set streaming for received data. | |
getStream () | |
Get status of streaming for received data. | |
request ($method=null) | |
Send the HTTP request and return an HTTP response object. | |
Static Public Member Functions | |
static | encodeFormData ($boundary, $name, $value, $filename=null, $headers=array()) |
static | encodeAuthHeader ($user, $password, $type=self::AUTH_BASIC) |
Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method. | |
Public Attributes | |
const | GET = 'GET' |
HTTP request methods. | |
const | POST = 'POST' |
const | PUT = 'PUT' |
const | HEAD = 'HEAD' |
const | DELETE = 'DELETE' |
const | TRACE = 'TRACE' |
const | OPTIONS = 'OPTIONS' |
const | CONNECT = 'CONNECT' |
const | MERGE = 'MERGE' |
const | PATCH = 'PATCH' |
const | AUTH_BASIC = 'basic' |
Supported HTTP Authentication methods. | |
const | HTTP_1 = '1.1' |
HTTP protocol versions. | |
const | HTTP_0 = '1.0' |
const | CONTENT_TYPE = 'Content-Type' |
Content attributes. | |
const | CONTENT_LENGTH = 'Content-Length' |
const | ENC_URLENCODED = 'application/x-www-form-urlencoded' |
POST data encoding methods. | |
const | ENC_FORMDATA = 'multipart/form-data' |
const | VTYPE_SCALAR = 'SCALAR' |
Value types for Body key/value pairs. | |
const | VTYPE_FILE = 'FILE' |
Protected Member Functions | |
_setParameter ($type, $name, $value) | |
Set a GET or POST parameter - used by SetParameterGet and SetParameterPost. | |
_openTempStream () | |
Create temporary stream. | |
_prepareHeaders () | |
Prepare the request headers. | |
_prepareBody () | |
Prepare the request body (for POST and PUT requests) | |
_getParametersRecursive ($parray, $urlencode=false) | |
Helper method that gets a possibly multi-level parameters array (get or post) and flattens it. | |
_detectFileMimeType ($file) | |
Attempt to detect the MIME type of a file using available extensions. | |
Static Protected Member Functions | |
static | _flattenParametersArray ($parray, $prefix=null) |
Convert an array of parameters into a flat array of (key, value) pairs. | |
Protected Attributes | |
$config | |
$adapter = null | |
$uri = null | |
$headers = array() | |
$method = self::GET | |
$paramsGet = array() | |
$paramsPost = array() | |
$enctype = null | |
$raw_post_data = null | |
$auth | |
$files = array() | |
$body_field_order = array() | |
$cookiejar = null | |
$last_request = null | |
$last_response = null | |
$redirectCounter = 0 | |
$_unmaskStatus = false | |
$_queryBracketsEscaped = true | |
Static Protected Attributes | |
static | $_fileInfoDb = null |
__construct | ( | $uri = null , |
|
$config = null |
|||
) |
Constructor method.
Will create a new HTTP client. Accepts the target URL and optionally configuration array.
Zend_Uri_Http | string | $uri | |
array | $config | Configuration key-value pairs. |
|
protected |
Attempt to detect the MIME type of a file using available extensions.
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 | File path |
|
staticprotected |
Convert an array of parameters into a flat array of (key, value) pairs.
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.
array | $parray | |
string | $prefix |
|
protected |
Helper method that gets a possibly multi-level parameters array (get or post) and flattens it.
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
array | $parray | The parameters array |
bool | $urlencode | Whether to urlencode the name and value |
|
protected |
Create temporary stream.
|
protected |
Prepare the request body (for POST and PUT requests)
Zend_Http_Client_Exception |
|
protected |
Prepare the request headers.
|
protected |
Set a GET or POST parameter - used by SetParameterGet and SetParameterPost.
string | $type | GET or POST |
string | $name | |
string | $value |
|
static |
Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.
string | $user | |
string | $password | |
string | $type |
Zend_Http_Client_Exception |
|
static |
getAdapter | ( | ) |
Load the connection adapter.
getCookieJar | ( | ) |
Return the current cookie jar or null if none.
getHeader | ( | $key | ) |
Get the value of a specific header.
Note that if the header has more than one value, an array will be returned.
string | $key |
getLastRequest | ( | ) |
Get the last HTTP request as string.
getLastResponse | ( | ) |
Get the last HTTP response received by this client.
If $config['storeresponse'] is set to false, or no response was stored yet, will return null
getRedirectionsCount | ( | ) |
Get the number of redirections done on the last request.
getStream | ( | ) |
Get status of streaming for received data.
getUnmaskStatus | ( | ) |
Returns the currently configured unmask status.
getUri | ( | $as_string = false | ) |
Get the URI for the next request.
boolean | $as_string | If true, will return the URI as a string |
request | ( | $method = null | ) |
Send the HTTP request and return an HTTP response object.
string | $method |
Zend_Http_Client_Exception |
resetParameters | ( | $clearAll = false | ) |
Clear all GET and POST parameters.
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_*
bool | $clearAll | Should all data be cleared? |
setAdapter | ( | $adapter | ) |
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
Zend_Http_Client_Adapter_Interface | string | $adapter |
Zend_Http_Client_Exception |
setAuth | ( | $user, | |
$password = '' , |
|||
$type = self::AUTH_BASIC |
|||
) |
Set HTTP authentication parameters.
$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);
string | false | $user | User name or false disable authentication |
string | $password | Password |
string | $type | Authentication type |
Zend_Http_Client_Exception |
setConfig | ( | $config = array() | ) |
Set configuration parameters for this HTTP client.
Zend_Config | array | $config |
Zend_Http_Client_Exception |
setCookie | ( | $cookie, | |
$value = null |
|||
) |
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.
Zend_Http_Cookie | string | $cookie | |
string | null | $value | If "cookie" is a string, this is the cookie value. |
Zend_Http_Client_Exception |
setCookieJar | ( | $cookiejar = true | ) |
Set the HTTP client's cookie jar.
A cookie jar is an object that holds and maintains cookies across HTTP requests and responses.
Zend_Http_CookieJar | boolean | $cookiejar | Existing cookiejar object, true to create a new one, false to disable |
Zend_Http_Client_Exception |
setEncType | ( | $enctype = self::ENC_URLENCODED | ) |
setFileUpload | ( | $filename, | |
$formname, | |||
$data = null , |
|||
$ctype = null |
|||
) |
Set a file to upload (using a POST request)
Can be used in two ways:
1. $data is null (default): $filename is treated as the name if a local file which will be read and sent. Will try to guess the content type using mime_content_type(). 2. $data is set - $filename is sent as the file name, but $data is sent as the file contents and no file is read from the file system. In this case, you need to manually set the Content-Type ($ctype) or it will default to application/octet-stream.
string | $filename | Name of file to upload, or name to save as |
string | $formname | Name of form element to send as |
string | $data | Data to send (if null, $filename is read and sent) |
string | $ctype | Content type to use (if $data is set and $ctype is null, will be application/octet-stream) |
Zend_Http_Client_Exception |
setHeaders | ( | $name, | |
$value = null |
|||
) |
Set one or more request headers.
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.
string | array | $name | Header name, full header string ('Header: value') or an array of headers |
mixed | $value | Header value or null |
Zend_Http_Client_Exception |
setMethod | ( | $method = self::GET | ) |
Set the next request's method.
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 | $method |
Zend_Http_Client_Exception |
setParameterGet | ( | $name, | |
$value = null |
|||
) |
Set a GET parameter for the request.
Wrapper around _setParameter
string | array | $name | |
string | $value |
setParameterPost | ( | $name, | |
$value = null |
|||
) |
Set a POST parameter for the request.
Wrapper around _setParameter
string | array | $name | |
string | $value |
setRawData | ( | $data, | |
$enctype = null |
|||
) |
Set the raw (already encoded) POST data.
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.
string | resource | $data | |
string | $enctype |
setStream | ( | $streamfile = true | ) |
Set streaming for received data.
string | boolean | $streamfile | Stream file, true for temp file, false/null for no streaming |
setUnmaskStatus | ( | $status = true | ) |
Set the unmask feature for GET parameters as array.
Example: foo%5B0%5D=a&foo%5B1%5D=b becomes foo=a&foo=b
This is usefull for some services
boolean | $status |
setUri | ( | $uri | ) |
Set the URI for the next request.
Zend_Uri_Http | string | $uri |
Zend_Http_Client_Exception |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
const AUTH_BASIC = 'basic' |
Supported HTTP Authentication methods.
const CONNECT = 'CONNECT' |
const CONTENT_LENGTH = 'Content-Length' |
const CONTENT_TYPE = 'Content-Type' |
Content attributes.
const DELETE = 'DELETE' |
const ENC_FORMDATA = 'multipart/form-data' |
const ENC_URLENCODED = 'application/x-www-form-urlencoded' |
POST data encoding methods.
const GET = 'GET' |
HTTP request methods.
const HEAD = 'HEAD' |
const HTTP_0 = '1.0' |
const HTTP_1 = '1.1' |
HTTP protocol versions.
const MERGE = 'MERGE' |
const OPTIONS = 'OPTIONS' |
const PATCH = 'PATCH' |
const POST = 'POST' |
const PUT = 'PUT' |
const TRACE = 'TRACE' |
const VTYPE_FILE = 'FILE' |
const VTYPE_SCALAR = 'SCALAR' |
Value types for Body key/value pairs.