PHP code example of amphp / http-client-cookies

1. Go to this page and download the library: Download amphp/http-client-cookies 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-cookies example snippets




use Amp\Http\Client\Cookie\CookieInterceptor;
use Amp\Http\Client\Cookie\LocalCookieJar;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
use Amp\Http\Client\Response;

st('https://google.com/'));
$firstResponse->getBody()->buffer();

$secondResponse = $httpClient->request(new Request('https://google.com/'));
$secondResponse->getBody()->buffer();

$otherDomainResponse = $httpClient->request(new Request('https://amphp.org/'));
$otherDomainResponse->getBody()->buffer();

print "== first response stores cookies ==\r\n";
print \implode("\r\n", $firstResponse->getHeaderArray('set-cookie'));
print "\r\n\r\n";

print "== second request sends cookies again ==\r\n";
print \implode("\r\n", $secondResponse->getRequest()->getHeaderArray('cookie'));
print "\r\n\r\n";

print "== other domain request does not send cookies ==\r\n";
print \implode("\r\n", $otherDomainResponse->getRequest()->getHeaderArray('cookie'));