PHP code example of mechta-market / php-http-client

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

    

mechta-market / php-http-client example snippets


$httpClient = new HttpClient();
$response = $httpClient->get("example.org");

var_dump($response->successful());

$httpClient = new HttpClient();
$httpClient->withQueryParameters(["foo" => "bar", "test" => "value"]);
$response = $httpClient->get("example.org");

var_dump($response->successful());

$httpClient = new HttpClient();
$data = ["foo" => "bar"];
$response = $httpClient->post("example.org", $data);

var_dump($response->successful());

$httpClient = new HttpClient();
$data = ["foo" => "bar"];
$httpClient->withBody($data);

$response = $httpClient->post("example.org");

$httpClient = new HttpClient();
$httpClient->withToken("random_string_token_value");

$response = $httpClient->get("example.org");

$httpClient = new HttpClient();
$httpClient->withBasicAuth("user", "random_string_token_value");

$response = $httpClient->get("example.org");
shell
composer