PHP code example of dadapas / http-client

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

    

dadapas / http-client example snippets


use Dadapas\Http\Client as HttpClient;
use Dadapas\Http\Request;
use Dadapas\Http\Exception\HttpException;

try {
	$client = new HttpClient;

	// Make a get request to google
	$request = new Request('GET', "https://www.google.com")
		->withHeader('Content-Type', 'text/html');

	// Return the response to the $response variable
	$response = $client->sendRequest($request);

} catch (HttpException $e) {

	echo $e->getMessage();
}


$response->status();   // Ok
$response->code() ;    // 200
$response->json();     // Return an array of application empty array instead
$response->toString(); // to get the response to string