我如何将Cookies设置为GuzzleHttp?

问题描述 投票:0回答:1

我如何通过发送带有自定义Cookie的请求来使用GuzzleHttp来获取页面内容?

php guzzle
1个回答
0
投票

您必须使用饼干罐:

$client = new \GuzzleHttp\Client();
$jar = new \GuzzleHttp\Cookie\CookieJar();

$jar->setCookie(new \GuzzleHttp\Cookie\SetCookie([
    'Name'     => ...,
    'Value'    => ...,
    'Domain'   => ...,
    'Path'     => '/',
    'Max-Age'  => ...,
    'Expires'  => ...,
    'Secure'   => ...,
    'Discard'  => ...,
    'HttpOnly' => ...
]));
$client->request('GET', '/get', ['cookies' => $jar]);
© www.soinside.com 2019 - 2024. All rights reserved.