php-如何在Goutte中设置cookie?

我不知道如何在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);
上一篇:PHP setcookie 网络函数


下一篇:php – 如何在CodeIgniter中检索cookie值?