PHP code example of amphp / http-client-psr7
1. Go to this page and download the library: Download amphp/http-client-psr7 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/ */
amphp / http-client-psr7 example snippets
mp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Psr7\PsrAdapter;
use Amp\Http\Client\Psr7\PsrHttpClient;
use Laminas\Diactoros\RequestFactory;
use Laminas\Diactoros\ResponseFactory;
// Note the laminas/laminas-diactoros library is used only as an example.
// You can use any library providing an implementation of PSR-17.
// PSR-17 request factory
$psrRequestFactory = new RequestFactory();
// PSR-17 response factory
$psrResponseFactory = new ResponseFactory();
$psrAdapter = new PsrAdapter($psrRequestFactory, $psrResponseFactory);
$ampHttpClient = HttpClientBuilder::buildDefault();
$psrHttpClient = new PsrHttpClient($ampHttpClient, $psrAdapter);
$request = $psrRequestFactory->createRequest('GET', 'https://google.com');
// $response is a PSR-7 ResponseInterface instance.
$response = $psrHttpClient->sendRequest($request);