Laravel和Cookies中的GuzzleHttp

时间:2019-05-11 06:56:35

标签: php http cookies guzzle

我在以下变量中包含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客户端以进行身份​​验证,如以下图像所示:

enter image description here

我该怎么做?

谢谢!

1 个答案:

答案 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]);