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', '/');
As described earlier, you can get the body of a response using the getBody() method. Guzzle uses the json_decode() method of PHP and uses arrays rather than stdClass objects for objects. You can use the xml() method when working with XML data.
Sending Requests You can create a request and then send the request with the client when you're ready: use GuzzleHttp\Psr7\Request; $request = new Request('PUT', 'http://httpbin.org/put'); $response = $client->send($request, ['timeout' => 2]);
Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interface for building query strings, POST requests, streaming large uploads, streaming large downloads, using HTTP cookies, uploading JSON data, etc...
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With