PHP code example of ajayvohra2005 / hack-http-client
1. Go to this page and download the library: Download ajayvohra2005/hack-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/ */
ajayvohra2005 / hack-http-client example snippets
use namespace HackHttp\Message as HM;
use namespace HackHttp\Client as HC;
<<__EntryPoint>>
function quick_start(): void
{
quest('GET', 'https://docs.hhvm.com/hack/');
echo $response->getStatusCode(); // 200
echo $response->getHeaderLine('content-type'); // 'text/html'
echo $response->getBody()->__toString(); // <!DOCTYPE html><html>...
// Send an asynchronous request.
$request = new HM\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($request)->then( (mixed $response): void ==> {
if($response is HM\Response) {
echo 'I completed! ' . $response->getBody()->__toString();
}
});
$promise->wait();
}