如何从Guzzle客户端检索cookie?

时间:2017-07-10 22:30:59

标签: php guzzle

如何在发出请求后从Guzzle请求/客户端检索Cookie?

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

1 个答案:

答案 0 :(得分:13)

请阅读the docs。您必须使用CookieJar类来处理cookie。

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

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