Guzzle请求URL时附带Cookie

就不长篇大论了,直接贴示例代码吧

$client = new \GuzzleHttp\Client();

$jar = new \GuzzleHttp\Cookie\CookieJar();
$domain = 'www.baidu.com';
$cookies = [
    'sessionid' => '123456',
]; 
$cookieJar = $jar->fromArray($cookies, $domain);

return $client->request('GET', 'www.baidu.com', ['cookies' => $cookieJar]);

Leave a Reply

Your email address will not be published. Required fields are marked *