Basic HTTP client used for talking with APIs.
PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
tests
.coveralls.yml
.gitignore
.scrutinizer.yml
.travis.yml
README.md
composer.json
ruleset.xml

README.md

Generic HTTP Client

A basic HTTP client used for talking with APIs.

Build Status Coverage Status Code Climate Scrutinizer Code Quality

Example

$transport = new \HttpClient\Transport\Socks();
$transport->setHost('http-client.serbang');

try {
    $transport->connect();
    $transport->request()->setPath('/tests/providers/response/text-chunked.php');
    $transport->request()->setBody(generateRandomString(10));
    $transport->request()->headers()->add('Connection', 'keep-alive');
    $transport->request()->headers()->add('Content-type', 'application/json');
    $transport->send();
    $transport->read();
    $transport->close();

    // Debug.
    echo "\n" . '---Begin Headers Body---' . "\n";
    var_dump($transport->getResponse()->getHeaders());
    echo "---End Headers Body---\n";
    echo "\n" . '---Begin Response Body---' . "\n";
    var_dump($transport->getResponse()->getBody());
    echo "---End Response Body---\n";

} catch (\HttpClient\Transport\Exception\Exception $e) {
    var_dump($e->getCode());
    var_dump($e->getMessage());
} catch (\HttpClient\Transport\Exception\RuntimeException $e) {
    var_dump($e->getCode());
    var_dump($e->getMessage());
}

External references: