2017 © Pedro Peláez
 

library incutio-php-http-client

HttpClient is a client class for the HTTP protocol.

image

walker/incutio-php-http-client

HttpClient is a client class for the HTTP protocol.

  • Monday, October 3, 2016
  • by walker
  • Repository
  • 4 Watchers
  • 16 Stars
  • 189 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 0 Open issues
  • 1 Versions
  • 10 % Grown

The README.md

About

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)

Instantiation

$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)

Basic Authentication

If the API you are accessing using this library requires basic authentication:, (*6)

$client->setAuthorization('username', 'password');

GET

$data can be an object or array. $headers should be an array, (*7)

$client->get('/service/endpoint', $data, $headers);

POST

$data can be a string, object, or array. $headers should be an array, (*8)

$client->post('/service/endpoint', $data, $headers);

PUT

$data can be a string, object, or array. $headers should be an array, (*9)

$client->put('/service/endpoint', $data, $headers);

DELETE

$data can be a string, object, or array. $headers should be an array, (*10)

$client->put('/service/endpoint', $data, $headers)

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)

Referer

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);

Response Content

Get the content returned by the most recent URL call., (*16)

$client->getContent();

Response Headers

You can get just the status or all the headers from your most recent URL call:, (*17)

$client->getStatus();
$client->getHeaders();

The Versions

03/10 2016

dev-master

9999999-dev https://github.com/walker/incutio-php-http-client

HttpClient is a client class for the HTTP protocol.

  Sources   Download

The MIT License

The Requires

  • php >=5.2.0

 

php class httpclient