PHP code example of osti / http-client-php

1. Go to this page and download the library: Download osti/http-client-php 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/ */

    

osti / http-client-php example snippets


use HttpClient;

// Create an instance of HttpClient
$http = new HttpClient();

// Make an HTTP GET request
$response = $http->makeRequest('GET', 'https://www.example.com');

// Handle the response
if ($response !== false) {
    // The request was successful
    echo $response; // Response content
} else {
    // An error occurred during the request
    echo "Error during the request.";
}

$http = new HttpClient($cookies = true, $verify = true);


$http->addHeaders([
    'User-Agent' => 'My User Agent',
    'Authorization' => 'Bearer Token123'
]);

$http->setBody([
    'query' => ['key' => 'value'],
    'json' => ['data' => 'content']
]);