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

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Captcha Code