Class Zend_Http_Client

Description

Zend_Http_Client is an implemetation 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 persistance (using a Zend_Http_Cookiejar object)

  • license: New BSD License
  • copyright: Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)

Located in /Http/Client.php (line 41)

Zend_Http_Client_Abstract
   |
   --Zend_Http_Client
Class Constant Summary
 AUTH_BASIC = 'basic'
Variable Summary
Method Summary
 static string encodeAuthHeader (string $user, string $password, [string $type = self::AUTH_BASIC])
 static string encodeFormData (string $boundary, string $name, mixed $value, [string $filename = null], [array $headers = array()])
 Zend_Http_Response request ([string $method = null])
 void resetParameters ()
 void setAuth (string|false $user, [string $password = ''], [string $type = self::AUTH_BASIC])
 void setCookie (Zend_Http_Cookie|string $cookie, [string|null $value = null])
 void setCookiejar ([Zend_Http_Cookiejar|boolean $cookiejar = true])
 void setFileUpload (string $filename, string $formname, [string $data = null], [string $ctype = null])
 void setMaxRedirects ([int $redirects = 5])
 void setProxy (string|null $host, [int $port = 8080], [string $user = null], [string $password = null])
 void setStrictRedirects ([boolean $strict = true])
 resource _connect ()
 array _getParametersRecursive (array $parray, [bool $urlencode = false])
 string _prepare_body ()
 string _prepare_headers ()
 string _read (resource $socket)
 void _write (resource $socket, string $request)
Variables
array|null $auth (line 94)

HTTP Authentication settings

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.

  • access: protected
Zend_Http_Cookiejar $Cookiejar = null (line 111)

The client's cookie jar

  • access: protected
boolean $doStrictRedirects = false (line 73)

Whether to strictly follow RFC 2616 when redirecting

If true, 301 & 302 responses will be treated as written in the RFC - that is the same request method will be used in the new request. If false (default), a GET request is always used in the next request.

  • access: protected
array $files = array() (line 104)

File upload arrays (used in POST requests)

An associative array, where each element is of the format: 'name' => array('filename.txt', 'text/plain', 'This is the actual file contents')

  • access: protected
int $maxRedirects = 5 (line 55)

Maximum number of redirections to follow, 0 for none.

  • access: protected
array $proxy = array('host' => null, 'port' => null, 'user' => null, 'password' => null) (line 80)

HTTP proxy settings

  • access: protected
int $redirectCounter = 0 (line 62)

Redirection counter

  • access: protected

Inherited Variables

Inherited from Zend_Http_Client_Abstract

Zend_Http_Client_Abstract::$enctype
Zend_Http_Client_Abstract::$headers
Zend_Http_Client_Abstract::$http_version
Zend_Http_Client_Abstract::$last_request
Zend_Http_Client_Abstract::$method
Zend_Http_Client_Abstract::$paramsGet
Zend_Http_Client_Abstract::$paramsPost
Zend_Http_Client_Abstract::$raw_post_data
Zend_Http_Client_Abstract::$timeout
Zend_Http_Client_Abstract::$uri
Zend_Http_Client_Abstract::$user_agent
Methods
static encodeAuthHeader (line 636)

Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.

string encodeAuthHeader (string $user, string $password, [string $type = self::AUTH_BASIC])
  • string $user
  • string $password
  • string $type
static encodeFormData (line 609)

Encode date to a multipart/form-data part suitable for a POST request.

  • access: public
string encodeFormData (string $boundary, string $name, mixed $value, [string $filename = null], [array $headers = array()])
  • string $boundary
  • string $name
  • mixed $value
  • string $filename
  • array $headers: Associative array of optional headers @example ("Content-transfer-encoding" => "binary")
getCookiejar (line 224)

Return the current cookie jar or null if none.

  • access: public
Zend_Http_Cookiejar|null getCookiejar ()
getLastRedirectionsCount (line 139)

Get the number of redirections done on the last request

  • access: public
int getLastRedirectionsCount ()
request (line 309)

Send the HTTP request and return an HTTP response object

  • access: public
Zend_Http_Response request ([string $method = null])
  • string $method

Redefinition of:
Zend_Http_Client_Abstract::request()
Send the HTTP request and return a response
resetParameters (line 262)

Clear all GET and POST parameters

Should be used to reset the request parameters if the client is used for several concurrent requests.

  • access: public
void resetParameters ()

Redefinition of:
Zend_Http_Client_Abstract::resetParameters()
Clear all GET and POST parameters
setAuth (line 178)

Set HTTP authentication parameters

$type should be one of the supported types - see the self::AUTH_* constants.

To enable authentication:

void setAuth (string|false $user, [string $password = ''], [string $type = self::AUTH_BASIC])
  • string|false $user: User name or false disable authentication
  • string $password: Password
  • string $type: Authentication type
setCookie (line 236)

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.

  • access: public
void setCookie (Zend_Http_Cookie|string $cookie, [string|null $value = null])
  • Zend_Http_Cookie|string $cookie
  • string|null $value: If "cookie" is a string, this is the cookie value.

Redefinition of:
Zend_Http_Client_Abstract::setCookie()
Set a cookie parameter
setCookiejar (line 206)

Set the HTTP client's cookie jar.

A cookie jar is an object that holds and maintains cookies across HTTP requests and responses.

  • access: public
void setCookiejar ([Zend_Http_Cookiejar|boolean $cookiejar = true])
  • Zend_Http_Cookiejar|boolean $cookiejar: Exisitng cookiejar object, true to create a new one, false to disable
setFileUpload (line 287)

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.

  • access: public
void setFileUpload (string $filename, string $formname, [string $data = null], [string $ctype = null])
  • 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)
setMaxRedirects (line 118)

Set the number of maximum redirections to follow, 0 for none.

  • access: public
void setMaxRedirects ([int $redirects = 5])
  • int $redirects
setProxy (line 152)

Set a proxy server for the request

  • access: public
void setProxy (string|null $host, [int $port = 8080], [string $user = null], [string $password = null])
  • string|null $host: Hostname or null to disable proxy
  • int $port
  • string $user
  • string $password
setStrictRedirects (line 129)

Set whether to strictly follow RFC 2616 when redirecting or not (See documentation for Zend_Http_Client::doStrictRedirects for details)

  • access: public
void setStrictRedirects ([boolean $strict = true])
  • boolean $strict
_connect (line 521)

Open a connection to the remote server

  • return: Socket
  • access: protected
resource _connect ()

Redefinition of:
Zend_Http_Client_Abstract::_connect()
Open a connection to the remote server
_getParametersRecursive (line 576)

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.

  • access: protected
array _getParametersRecursive (array $parray, [bool $urlencode = false])
  • array $parray: The parameters array
  • bool $urlencode: Whether to urlencode the name and value
_prepare_body (line 453)

Prepare the request body (for POST and PUT requests)

  • access: protected
string _prepare_body ()

Redefinition of:
Zend_Http_Client_Abstract::_prepare_body()
Prepare the request body (for POST and PUT requests)
_prepare_headers (line 370)

Prepare the request headers

  • access: protected
string _prepare_headers ()

Redefinition of:
Zend_Http_Client_Abstract::_prepare_headers()
Prepare the request headers
_read (line 552)

Read response from remote server

  • access: protected
string _read (resource $socket)
  • resource $socket: Socket (returned by _connect())

Redefinition of:
Zend_Http_Client_Abstract::_read()
Read response from remote server
_write (line 541)

Send request to the remote server

  • access: protected
void _write (resource $socket, string $request)
  • resource $socket: Socket (returned by _connect())
  • string $request: Request to send

Redefinition of:
Zend_Http_Client_Abstract::_write()
Send request to the remote server

Inherited Methods

Inherited From Zend_Http_Client_Abstract

 Zend_Http_Client_Abstract::__construct()
 Zend_Http_Client_Abstract::delete()
 Zend_Http_Client_Abstract::get()
 Zend_Http_Client_Abstract::getHeader()
 Zend_Http_Client_Abstract::getLastRequest()
 Zend_Http_Client_Abstract::getMethod()
 Zend_Http_Client_Abstract::getUri()
 Zend_Http_Client_Abstract::post()
 Zend_Http_Client_Abstract::put()
 Zend_Http_Client_Abstract::request()
 Zend_Http_Client_Abstract::resetParameters()
 Zend_Http_Client_Abstract::setCookie()
 Zend_Http_Client_Abstract::setEncType()
 Zend_Http_Client_Abstract::setHeader()
 Zend_Http_Client_Abstract::setHeaders()
 Zend_Http_Client_Abstract::setMethod()
 Zend_Http_Client_Abstract::setParameterGet()
 Zend_Http_Client_Abstract::setParameterPost()
 Zend_Http_Client_Abstract::setRawData()
 Zend_Http_Client_Abstract::setTimeout()
 Zend_Http_Client_Abstract::setUri()
 Zend_Http_Client_Abstract::setUserAgent()
 Zend_Http_Client_Abstract::validateHeaders()
 Zend_Http_Client_Abstract::_connect()
 Zend_Http_Client_Abstract::_prepare_body()
 Zend_Http_Client_Abstract::_prepare_headers()
 Zend_Http_Client_Abstract::_read()
 Zend_Http_Client_Abstract::_setParameter()
 Zend_Http_Client_Abstract::_write()
Class Constants

Documentation generated on Fri, 30 Jun 2006 11:29:47 -0500 by phpDocumentor 1.3.0RC6