Client
class Client
This class is an implemetation of an HTTP client in PHP.
It supports basic HTTP 1.0 and 1.1 requests. For a more complete implementation try Zend_Http_Client.
Methods
Constructor method. Will create a new HTTP client. Accepts the target URL and optionally configuration array.
Get the URI for the next request
Set a request header
Get the method for the next request
Get the value of a specific header
Set a GET parameter for the request.
Get a GET parameter for the request.
Get all the GET parameters
Get the number of redirections done on the last request
Set the raw (already encoded) POST data.
Get the raw (already encoded) POST data.
Clear all GET and POST parameters
Send the HTTP request and return an HTTP response object
Prepare the request headers
Details
at line 114
__construct(string $uri = null, array $config = null)
Constructor method. Will create a new HTTP client. Accepts the target URL and optionally configuration array.
at line 132
Client
setUri(string $uri)
Set the URI for the next request
at line 156
string
getUri(bool $asString = true)
Get the URI for the next request
at line 169
Client
setConfig(array $config = array())
Set configuration parameters for this HTTP client
at line 192
Client
setHeaders(string $name, string $value = null)
Set a request header
at line 217
Client
setMethod(string $method)
Set the next request's method
Validated the passed method and sets it.
at line 233
string
getMethod()
Get the method for the next request
at line 248
string|array|null
getHeader(string $key)
Get the value of a specific header
Note that if the header has more than one value, an array will be returned.
at line 266
Client
setParameterGet(string $name, string $value = null)
Set a GET parameter for the request.
at line 286
string
getParameterGet(string $name)
Get a GET parameter for the request.
at line 300
array
getParametersGet()
Get all the GET parameters
at line 310
int
getRedirectionsCount()
Get the number of redirections done on the last request
at line 329
Client
setRawData(string|resource $data)
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.
at line 340
string
getRawData()
Get the raw (already encoded) POST data.
at line 358
Client
resetParameters(bool $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
at line 388
Response
request(null|string $method = null)
Send the HTTP request and return an HTTP response object
at line 543
protected array
prepareHeaders($host, $port)
Prepare the request headers