How to retrieve cookies from Guzzle client?

0

Issue

How can I retrieve the cookies from a Guzzle request / client, after a request has occurred?

$client = new Client([
    'base_uri' => 'www.google.com',
]);
$response = $client->request('GET', '/');

Solution

Read the docs, please. You have to use CookieJar class to work with cookies.

$client = new \GuzzleHttp\Client(['cookies' => true]);
$r = $client->request('GET', 'http://httpbin.org/cookies');

$cookieJar = $client->getConfig('cookies');
$cookieJar->toArray();

Answered By – Alexey Shokov

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More