PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTTP » HTTP_Client » Manual

Class Summary HTTP_Client

Class Summary HTTP_Client – A simple HTTP client class.

HTTP_Client

A simple HTTP client class. The class wraps around HTTP_Request providing a higher-level API for performing multiple HTTP requests. It handles HTTP redirects, stores cookies and sets referrers between requests.

Class Trees for HTTP_Client

constructor HTTP_Client::HTTP_Client()

constructor HTTP_Client::HTTP_Client() – Constructor

Synopsis

require_once 'HTTP/Client.php';

void constructor HTTP_Client::HTTP_Client ( array $defaultRequestParams = null , array $defaultHeaders = null )

Description

Sets default request parameters and default headers.

Parameter

array $defaultRequestParams

Parameters to pass to HTTP_Request's constructor

array $defaultHeaders

Default headers to send on every request

Throws

throws no exceptions thrown

See

see setDefaultHeader(), setRequestParameter()

Note

This function can not be called statically.

HTTP_Client::attach()

HTTP_Client::attach() – Adds a Listener to the list of listeners that are notified of the object's events

Synopsis

require_once 'HTTP/Client.php';

boolean HTTP_Client::attach ( object HTTP_Request_Listener &$listener , boolean $propagate = false )

Description

The attached Listeners are notified of the following events:

'request'
sent before a HTTP request that is not a result of previous redirect.
'httpSuccess'
sent upon receiving a successfull 2xx response (or 3xx response, if it is not a redirect or if redirect processing is disabled).
'httpRedirect'
sent when a 3xx redirection response is received, before following a redirect
'httpError'
sent on 4xx, 5xx response

If $propagate is TRUE the Listener will be attached to the created HTTP_Request objects and will be notified of their events as well.

Parameter

object HTTP_Request_Listener &$listener

Listener instance to attach

boolean $propagate

Whether the listener should be attached to the created HTTP_Request objects

Return value

returns whether the listener was successfully attached

Throws

throws no exceptions thrown

See

see detach()

Note

This function can not be called statically.

HTTP_Client::currentResponse()

HTTP_Client::currentResponse() – Returns the most recent HTTP response

Synopsis

require_once 'HTTP/Client.php';

array& HTTP_Client::currentResponse ( )

Description

The returned array has the following keys: 'code', 'headers', 'body'.

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTTP_Client::detach()

HTTP_Client::detach() – Removes a Listener from the list of listeners

Synopsis

require_once 'HTTP/Client.php';

boolean HTTP_Client::detach ( object HTTP_Request_Listener &$listener )

Description

This package is not documented yet.

Parameter

object HTTP_Request_Listener &$listener

Listener instance to detach

Return value

returns whether the listener was successfully detached

Throws

throws no exceptions thrown

See

see attach()

Note

This function can not be called statically.

HTTP_Client::get()

HTTP_Client::get() – Sends a 'GET' HTTP request

Synopsis

require_once 'HTTP/Client.php';

integer HTTP_Client::get ( string $url , mixed $data = null , boolean $preEncoded = false )

Description

This package is not documented yet.

Parameter

string $url

URL

mixed $data

additional data to send

boolean $preEncoded

Whether the data is already urlencoded

Return value

returns HTTP response code

Throws

throws PEAR_Error

Note

This function can not be called statically.

HTTP_Client::head()

HTTP_Client::head() – Sends a 'HEAD' HTTP request

Synopsis

require_once 'HTTP/Client.php';

integer HTTP_Client::head ( string $url )

Description

This package is not documented yet.

Parameter

string $url

URL

Return value

returns HTTP response code

Throws

throws PEAR_Error

Note

This function can not be called statically.

HTTP_Client::post()

HTTP_Client::post() – Sends a 'POST' HTTP request

Synopsis

require_once 'HTTP/Client.php';

integer HTTP_Client::post ( string $url , mixed $data , boolean $preEncoded = false , array $files = array() )

Description

This package is not documented yet.

Parameter

string $url

URL

mixed $data

Data to send

boolean $preEncoded

Whether the data is already urlencoded

array $files

Files to upload. Elements of the array should have the form: array(name, filename(s)[, content type]), see HTTP_Request::addFile()

Return value

returns HTTP response code

Throws

throws PEAR_Error

Note

This function can not be called statically.

HTTP_Client::reset()

HTTP_Client::reset() – Clears object's internal properties

Synopsis

require_once 'HTTP/Client.php';

void HTTP_Client::reset ( )

Description

This package is not documented yet.

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTTP_Client::setDefaultHeader()

HTTP_Client::setDefaultHeader() – Sets default header(s) for HTTP requests

Synopsis

require_once 'HTTP/Client.php';

void HTTP_Client::setDefaultHeader ( mixed $name , string $value = null )

Description

These are standard HTTP headers that will be sent by all created HTTP_Request objects.

Parameter

mixed $name

header name or array ('header name' => 'header value')

string $value

header value if $name is not an array

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTTP_Client::setMaxRedirects()

HTTP_Client::setMaxRedirects() – Sets the maximum number of redirects that will be processed.

Synopsis

require_once 'HTTP/Client.php';

void HTTP_Client::setMaxRedirects ( int $value )

Description

Setting this value to 0 disables redirect processing. If it is not 0 and the number of redirects after a request is bigger than this number, then an error will be raised.

Parameter

integer $value

Max number of redirects to process

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTTP_Client::setRequestParameter()

HTTP_Client::setRequestParameter() – Sets parameter(s) for HTTP requests

Synopsis

require_once 'HTTP/Client.php';

void HTTP_Client::setRequestParameter ( mixed $name , string $value = null )

Description

These parameters will be passed to constructors of created HTTP_Request instances.

Parameter

mixed $name

parameter name or array ('parameter name' => 'parameter value')

string $value

parameter value if $name is not an array

Throws

throws no exceptions thrown

Note

This function can not be called statically.

Class Summary HTTP_Client_CookieManager

Class Summary HTTP_Client_CookieManager – Stores cookies and passes them between HTTP requests.

HTTP_Client_CookieManager

Stores cookies and passes them between HTTP requests. While this class is a part of HTTP_Client package, it can be used separately.

Class Trees for HTTP_Client_CookieManager

constructor HTTP_Client_CookieManager::HTTP_Client_CookieManager()

constructor HTTP_Client_CookieManager::HTTP_Client_CookieManager() – Constructor

Synopsis

require_once 'HTTP/Client/CookieManager.php';

void constructor HTTP_Client_CookieManager::HTTP_Client_CookieManager ( )

Description

This package is not documented yet.

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTTP_Client_CookieManager::addCookie()

HTTP_Client_CookieManager::addCookie() – Explicitly adds cookie to the list

Synopsis

require_once 'ClientCookieManager.php';

void HTTP_Client_CookieManager::addCookie ( array $cookie )

Description

This package is not documented yet.

Parameter

array $cookie

An array representing cookie, this function expects all of the array's fields ('name', 'value', 'domain', 'path', 'expires', 'secure') to be set.

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTTP_Client_CookieManager::passCookies()

HTTP_Client_CookieManager::passCookies() – Adds cookies to the request

Synopsis

require_once 'HTTP/Client/CookieManager.php';

void HTTP_Client_CookieManager::passCookies ( object An &$request )

Description

The method sends only the cookies that should be sent with the request and it adds them in right order.

Parameter

object HTTP_Request &$request

HTTP_Request object

Throws

throws no exceptions thrown

See

see updateCookies(), addCookie()

Note

This function can not be called statically.

HTTP_Client_CookieManager::reset()

HTTP_Client_CookieManager::reset() – Clears the cookies list

Synopsis

require_once 'HTTP/Client/CookieManager.php';

void HTTP_Client_CookieManager::reset ( )

Description

This package is not documented yet.

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTTP_Client_CookieManager::updateCookies()

HTTP_Client_CookieManager::updateCookies() – Updates cookie list from HTTP server response

Synopsis

require_once 'HTTP/Client/CookieManager.php';

void HTTP_Client_CookieManager::updateCookies ( object HTTP_Request &$request )

Description

This method gets the cookies from HTTP response received by HTTP_Request instance and adds them to the object's internal list.

Parameter

object HTTP_Request &$request

HTTP_Request object containing the HTTP response, i.e. its sendRequest() should already be called.

Throws

throws no exceptions thrown

See

see passCookies(), addCookie()

Note

This function can not be called statically.