我在以下变量中包含cookie内容:
$cookie = $res->getHeader('Set-Cookie')[0];
=> "mobrain_api=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; expires=Sun, 12-May-2019 06:25:33 GMT; Max-Age=86400; path=/; httponly"
我想将此字符串传递给Guzzle客户端以进行身份验证,如以下图像所示:
我该怎么做?
谢谢!
答案 0 :(得分:0)
尝试按原样将其传递给CookieJar,described in the docs:
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Cookie\SetCookie;
$client = new Client();
$jar = new CookieJar();
$jar->setCookie(SetCookie::fromString($cookie));
$client->request('GET', '/v1/campaign/feed', ['cookies' => $jar]);