当前位置: 首页 > 工具软件 > Goutte > 使用案例 >

php中怎么设置cookie,php-如何在Goutte中设置cookie?

缪坚诚
2023-12-01

我不知道如何在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?

解决方法:

食尸鬼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);

标签:setcookie,goutte,cookies,php

来源: https://codeday.me/bug/20191028/1950442.html

 类似资料: