dev-master
9999999-dev https://github.com/walker/incutio-php-http-clientHttpClient is a client class for the HTTP protocol.
The MIT License
The Requires
- php >=5.2.0
php class httpclient
HttpClient is a client class for the HTTP protocol.
This is a continuation of the Incutio PHP HTTP Client class. It's still one of the better standalone HTTP client classes out there. I'm just going to make it do more., (*1)
Of all I can find on the HTTP spec, body content is allowed with POST, PUT, and DELETE requests, so we allow you to send body content when using this client., (*2)
$client = new HttpClient('www.domain.com', 80);
Where the first argument is the domain and the second is the port. The port is optional and default to 80 if not provided., (*3)
If you'd like to instantiate on an https:// URL, add it to the domain:, (*4)
$client = new HttpClient('https://www.domain.com');
This will automatically use port 443 when connecting., (*5)
If the API you are accessing using this library requires basic authentication:, (*6)
$client->setAuthorization('username', 'password');
$data
can be an object or array.
$headers
should be an array, (*7)
$client->get('/service/endpoint', $data, $headers);
$data
can be a string, object, or array.
$headers
should be an array, (*8)
$client->post('/service/endpoint', $data, $headers);
$data
can be a string, object, or array.
$headers
should be an array, (*9)
$client->put('/service/endpoint', $data, $headers);
$data
can be a string, object, or array.
$headers
should be an array, (*10)
$client->put('/service/endpoint', $data, $headers)
Content-Type on requests is no longer set by default., (*11)
If Accept is not set, it defaults to:, (*12)
'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,image/jpeg,image/gif,*/*'
Headers should be things like:, (*13)
array('Accept'=>'application/json', 'Content-Type':'text/xml', 'etc')
$data
and $headers
are optional in all of these., (*14)
The Incutio library used to set the referer of a call as the last item called. I rarely find this helpful, so it's turned off by default now. To turn it back on:, (*15)
$this->client->setPersistReferers(true);
Get the content returned by the most recent URL call., (*16)
$client->getContent();
You can get just the status or all the headers from your most recent URL call:, (*17)
$client->getStatus(); $client->getHeaders();
HttpClient is a client class for the HTTP protocol.
The MIT License
php class httpclient