class HttpClient implements HttpClientInterface (View source)

The HttpClient class.

Methods

__construct(array $options = array(), TransportInterface $transport = null)

Class init.

ResponseInterface
request(string $method, string|object $url, mixed $data = null, array $headers = array())

Request a remote server.

ResponseInterface
download(string|object $url, string $dest, mixed $data = null, array $headers = array())

Download file to target path.

ResponseInterface
send(RequestInterface $request)

Send a request to remote.

ResponseInterface
options(string $url, array $headers = array())

Method to send the OPTIONS command to the server.

ResponseInterface
head(string $url, array $headers = array())

Method to send the HEAD command to the server.

ResponseInterface
get(string $url, mixed $data = null, array $headers = array())

Method to send the GET command to the server.

ResponseInterface
post(string $url, mixed $data, array $headers = array())

Method to send the POST command to the server.

ResponseInterface
put(string $url, mixed $data, array $headers = array())

Method to send the PUT command to the server.

ResponseInterface
delete(string $url, mixed $data = null, array $headers = array())

Method to send the DELETE command to the server.

ResponseInterface
trace(string $url, array $headers = array())

Method to send the TRACE command to the server.

ResponseInterface
patch(string $url, mixed $data, array $headers = array())

Method to send the PATCH command to the server.

mixed
getOption(string $name, mixed $default = null)

Get option value.

setOption(string $name, mixed $value)

Set option value.

array
getOptions()

Method to get property Options

setOptions(array $options)

Method to set property options

getTransport()

Method to get property Transport

setTransport(TransportInterface $transport)

Method to set property transport

Details

at line line 47
__construct(array $options = array(), TransportInterface $transport = null)

Class init.

Parameters

array $options The options of this client object.
TransportInterface $transport The Transport handler, default is CurlTransport.

at line line 65
ResponseInterface request(string $method, string|object $url, mixed $data = null, array $headers = array())

Request a remote server.

This method will build a Request object and use send() method to send request.

Parameters

string $method The method type.
string|object $url The URL to request, may be string or Uri object.
mixed $data The request body data, can be an array of POST data.
array $headers The headers array.

Return Value

ResponseInterface

at line line 82
ResponseInterface download(string|object $url, string $dest, mixed $data = null, array $headers = array())

Download file to target path.

Parameters

string|object $url The URL to request, may be string or Uri object.
string $dest The dest file path can be a StreamInterface.
mixed $data The request body data, can be an array of POST data.
array $headers The headers array.

Return Value

ResponseInterface

at line line 103
ResponseInterface send(RequestInterface $request)

Send a request to remote.

Parameters

RequestInterface $request The Psr Request object.

Return Value

ResponseInterface

at line line 125
ResponseInterface options(string $url, array $headers = array())

Method to send the OPTIONS command to the server.

Parameters

string $url Path to the resource.
array $headers An array of name-value pairs to include in the header of the request.

Return Value

ResponseInterface

at line line 140
ResponseInterface head(string $url, array $headers = array())

Method to send the HEAD command to the server.

Parameters

string $url Path to the resource.
array $headers An array of name-value pairs to include in the header of the request.

Return Value

ResponseInterface

at line line 156
ResponseInterface get(string $url, mixed $data = null, array $headers = array())

Method to send the GET command to the server.

Parameters

string $url Path to the resource.
mixed $data Either an associative array or a string to be sent with the request.
array $headers An array of name-value pairs to include in the header of the request.

Return Value

ResponseInterface

at line line 172
ResponseInterface post(string $url, mixed $data, array $headers = array())

Method to send the POST command to the server.

Parameters

string $url Path to the resource.
mixed $data Either an associative array or a string to be sent with the request.
array $headers An array of name-value pairs to include in the header of the request

Return Value

ResponseInterface

at line line 188
ResponseInterface put(string $url, mixed $data, array $headers = array())

Method to send the PUT command to the server.

Parameters

string $url Path to the resource.
mixed $data Either an associative array or a string to be sent with the request.
array $headers An array of name-value pairs to include in the header of the request.

Return Value

ResponseInterface

at line line 204
ResponseInterface delete(string $url, mixed $data = null, array $headers = array())

Method to send the DELETE command to the server.

Parameters

string $url Path to the resource.
mixed $data Either an associative array or a string to be sent with the request.
array $headers An array of name-value pairs to include in the header of the request.

Return Value

ResponseInterface

at line line 219
ResponseInterface trace(string $url, array $headers = array())

Method to send the TRACE command to the server.

Parameters

string $url Path to the resource.
array $headers An array of name-value pairs to include in the header of the request.

Return Value

ResponseInterface

at line line 235
ResponseInterface patch(string $url, mixed $data, array $headers = array())

Method to send the PATCH command to the server.

Parameters

string $url Path to the resource.
mixed $data Either an associative array or a string to be sent with the request.
array $headers An array of name-value pairs to include in the header of the request.

Return Value

ResponseInterface

at line line 248
mixed getOption(string $name, mixed $default = null)

Get option value.

Parameters

string $name Option name.
mixed $default The default value if not exists.

Return Value

mixed The found value or default value.

at line line 266
HttpClient setOption(string $name, mixed $value)

Set option value.

Parameters

string $name Option name.
mixed $value The value you want to set in.

Return Value

HttpClient Return self to support chaining.

at line line 278
array getOptions()

Method to get property Options

Return Value

array

at line line 290
HttpClient setOptions(array $options)

Method to set property options

Parameters

array $options

Return Value

HttpClient Return self to support chaining.

at line line 312
TransportInterface getTransport()

Method to get property Transport

Return Value

TransportInterface

at line line 324
HttpClient setTransport(TransportInterface $transport)

Method to set property transport

Parameters

TransportInterface $transport

Return Value

HttpClient Return self to support chaining.