PHP code example of webignition / guzzle-request-headers-middleware

1. Go to this page and download the library: Download webignition/guzzle-request-headers-middleware 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/ */

    

webignition / guzzle-request-headers-middleware example snippets


use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use webignition\Guzzle\Middleware\RequestHeaders\RequestHeadersMiddleware;

// Creating a client that uses the middleware
$requestHeadersMiddleware = new RequestHeadersMiddleware();

$handlerStack = HandlerStack::create();
$handlerStack->push($requestHeadersMiddleware, 'request-headers');

$client = new Client([
    'handler' => $handlerStack,
]);

// Setting request headers
$requestHeadersMiddleware->setHeader('User-Agent', 'Super Foo!');

// All requests to example.com (or *.example.com) will now have
// a header of 'User-Agent: Super Foo!'

// Clearing request headers by explicitly setting a previously-set value to null
$requestHeadersMiddleware->setHeader('User-Agent', null);