似乎您以正确的方式提出了请求,传递了
CookieJarInterface
。但是,您不应该期望
Set-Cookie
标题。相反,请检查
罐子
检查返回了哪些Cookie。
以下示例显示了如何迭代所有Cookie:
$client = new \GuzzleHttp\Client();
$jar = new \GuzzleHttp\Cookie\CookieJar();
$request = $client->request('GET', 'https://www.google.com/', [
'cookies' => $jar
]);
$it = $jar->getIterator();
while ($it->valid()) {
var_dump($it->current());
$it->next();
}
以下是上述代码段的示例输出:
object(GuzzleHttp\Cookie\SetCookie)#36 (1) {
["data":"GuzzleHttp\Cookie\SetCookie":private]=>
array(9) {
["Name"]=>
string(3) "NID"
["Value"]=>
string(132) "130=dmyl6v*******"
["Domain"]=>
string(11) ".google.com"
["Path"]=>
string(1) "/"
["Max-Age"]=>
NULL
["Expires"]=>
int(1542242169)
["Secure"]=>
bool(false)
["Discard"]=>
bool(false)
["HttpOnly"]=>
bool(true)
}
}
请参阅
CookieJar
班
source
有关如何访问返回的Cookie的更多信息。此外,您可以查看
docs
对于
ArrayIterator
班