gpt4 book ai didi

php - 如何在 Goutte 中设置 cookie?

转载 作者:可可西里 更新时间:2023-11-01 00:59:41 25 4
gpt4 key购买 nike

我不知道如何在 Goutte 中设置 cookie。我正在尝试以下代码:

$client->setHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36');
$client->getCookieJar()->set('SRCHUID');

我附上了这个名字的 cookie 图片。我该如何设置这个 cookie?

enter image description here

最佳答案

Goutte 与 Guzzle 6

use GuzzleHttp\Cookie;

$cookieJar = new \GuzzleHttp\Cookie\CookieJar(true);

$cookieJar->setCookie(new \GuzzleHttp\Cookie\SetCookie([
'Domain' => "www.domain.com",
'Name' => $name,
'Value' => $value,
'Discard' => true
]));

$client = new Client();
$guzzleclient = new \GuzzleHttp\Client([
'timeout' => 900,
'verify' => false,
'cookies' => $cookieJar
]);
$client->setClient($guzzleclient);

return $client; //or do your normal client request here e.g $client->request('GET', $url);

关于php - 如何在 Goutte 中设置 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30993495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com