PHP code example of art4 / requests-psr18-adapter

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

    

art4 / requests-psr18-adapter example snippets




// First, include the Composer autoload.php
y' => '127.0.0.1:8080',
    'transport' => $customTransport,
    // other Requests options
];

// Create the HTTP client
$httpClient = new \Art4\Requests\Psr\HttpClient($options);

// Create a PSR-7 request and optional set other headers
$request = $httpClient->createRequest('GET', 'http://httpbin.org/get');
$request = $request->withHeader('Accept', 'application/json');

try {
    // Send the request
    $response = $httpClient->sendRequest($request);
} catch (\Psr\Http\Client\ClientExceptionInterface $th) {
    // Handle errors
    throw $th;
}

// Use the PSR-7 Response
var_dump($response->getBody()->__toString());