Coder Social home page Coder Social logo

jinguanio / incutio-php-http-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from walker/incutio-php-http-client

0.0 2.0 0.0 181 KB

This repository supports the continued development of the long moribund Incutio PHP HTTP Client Class.

PHP 100.00%

incutio-php-http-client's Introduction

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.

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.

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.

If you'd like to instantiate on an https:// URL, add it to the domain:

$client = new HttpClient('https://www.domain.com');

This will automatically use port 443 when connecting.

Basic Authentication

If the API you are accessing using this library requires basic authentication:

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

GET

$data can be an object or array. $headers should be an array

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

POST

$data can be a string, object, or array. $headers should be an array

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

PUT

$data can be a string, object, or array. $headers should be an array

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

DELETE

$data can be a string, object, or array. $headers should be an array

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

Headers

Content-Type on requests is no longer set by default.

If Accept is not set, it defaults to:

'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,image/jpeg,image/gif,*/*'

Headers should be things like:

array('Accept'=>'application/json', 'Content-Type':'text/xml', 'etc')

$data and $headers are optional in all of these.

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:

$this->client->setPersistReferers(true);

Response Content

Get the content returned by the most recent URL call.

$client->getContent();

Response Headers

You can get just the status or all the headers from your most recent URL call:

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

incutio-php-http-client's People

Contributors

walker avatar ysmood avatar rkgordon3 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.