PHP code example of setono / request-aware-http-client
1. Go to this page and download the library: Download setono/request-aware-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/ */
setono / request-aware-http-client example snippets
use Setono\RequestAwareHttpClient\RequestAwareHttpClient;
use Setono\RequestAwareHttpClient\RequestAwareHttpClientInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class YourService
{
private RequestAwareHttpClientInterface $httpClient;
public function __construct(HttpClientInterface $httpClient)
{
$this->httpClient = new RequestAwareHttpClient($httpClient);
}
public function doSomething(): void
{
$response = $this->httpClient->request('POST', 'https://httpbin.org/post', [
'json' => ['name' => 'John Doe']
]);
$request = $this->httpClient->getRequest($response);
echo $request->toString();
// Outputs:
// POST https://httpbin.org/post
// {
// "name": "John Doe"
// }
}
}