PHP code example of rokde / http-client

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

    

rokde / http-client example snippets


// GET (get from uri)
/** @var string $response */
$response = http('https://httpbin.org/get');

// POST (post data to uri)
/** @var \Rokde\HttpClient\Response $response */
$response = http()->post(['data' => 'value'], 'https://httpbin.org/post');

$client = new \Rokde\HttpClient\Client();

$request = new \Rokde\HttpClient\Request('https://httpbin.org/get', 'GET', [
  'accept' => 'application/json',
  'x-verify-test' => 'true',
]);

$response = $client->send($request);

if ($response->isOk()) {
  $resultString = $response->content();
}