Cookies

Guzzle可以使用 cookies 请求参数为你维护一个cookie会话,当发送一个请求时, cookies 选项必须设置成 GuzzleHttp\Cookie\CookieJarInterface 的实例。

  1. // Use a specific cookie jar
  2. $jar = new \GuzzleHttp\Cookie\CookieJar;
  3. $r = $client->request('GET', 'http://httpbin.org/cookies', [
  4. 'cookies' => $jar
  5. ]);

You can set cookies to true in a client constructor if you would like to use a shared cookie jar for all requests.

  1. // Use a shared client cookie jar
  2. $client = new \GuzzleHttp\Client(['cookies' => true]);
  3. $r = $client->request('GET', 'http://httpbin.org/cookies');