脚本宝典收集整理的这篇文章主要介绍了php – 将cookie从浏览器传递到Guzzle 6客户端,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
/** * First parameter is for cookie "strictness" */ $cookieJar = new \GuzzleHttp\Cookie\CookieJar(true); /** * Read in our cookies. In this case,they are coming From a * PSR7 compliant ServerRequestInterface such as Slim3 */ $cookies = $request->getCookieParams(); /** * Now loop through the cookies adding them to the jar */ foreach ($cookies as $cookie) { $newCookie =\GuzzleHttp\Cookie\SetCookie::fromString($cookie); /** * You can also do things such as $newCookie->setSecure(false); */ $cookieJar->setCookie($newCookie); } /** * Create a PSR7 guzzle request */ $guzzleRequest = new \GuzzleHttp\Psr7\Request( $request->getmethod(),$url,$headers,$body ); /** * Now actually PRepare Guzzle - here's where we hand over the * delicIoUs cookies! */ $client = new \GuzzleHttp\Client(['cookies'=>$cookieJar]); /** * Now get the response */ $guzzleResponse = $client->send($guzzleRequest,['timeout' => 5]);
以下是如何让它们再次出现:
$newCookies = $guzzleResponse->getHeader('set-cookie');
希望能帮助到你!
以上是脚本宝典为你收集整理的php – 将cookie从浏览器传递到Guzzle 6客户端全部内容,希望文章能够帮你解决php – 将cookie从浏览器传递到Guzzle 6客户端所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。