PHP code example of httptools / client

1. Go to this page and download the library: Download httptools/client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

httptools / client example snippets




use httptools\Client;

$http = new Client();

$http->Url('https://example.com');
$http->Method('POST');
$http->Headers([
    'Content-Type: application/json',
    'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXX'
]);
$http->Body('{"foo": "bar"}');
$http->Timeout(30);
echo $http->getBody();

$response = $http->Send();

$status = $http->getStatus();

$http->Option(CURLOPT_RETURNTRANSFER, true);

$response = $http->Url('https://example.com')
    ->Method('POST')
    ->Headers([
        'Content-Type: application/json',
        'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXX'
    ])
    ->Body('{"foo": "bar"}')
    ->Timeout(30)
    ->Send();

try {
    $response = $http->Send();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}