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
- 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.