zl程序教程

您现在的位置是:首页 >  Javascript

当前栏目

使用GuzzleHttp从HTTP调用获取cookie的值

2023-03-20 14:57:07 时间

前言

- 发送登录请求以后想看Cookies的值,文档只提供直接使用Cookie没有查看值的介绍,下面给大家讲一下实现代码。 实现代码

$client = new GuzzleHttpClient();

$jar = new GuzzleHttpCookieCookieJar();
$request = $client->request('GET', 'https://www.google.com/', [
    'cookies' => $jar
]);
 $it = $jar->getIterator();
    while ($it->valid()) {
        var_dump($it->current());
        $it->next();
  }

直接取值

$header = $res->getHeaders();
//var_dump($header);
$phpside = $header['Set-Cookie'][0];

本文来自投稿,不代表本站立场,如若转载,请注明出处:https://www.axiomxs.com/axiom/57.html