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);

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...