ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` ~~~ public function cookc() { //实例化客户端 $client = new \GuzzleHttp\Client(['cookie'=>true]); //构造url $url = 'https://www.taobao.com'; //设置代理请求 $res = $client->request('GET', $url)->getBody()->getContents(); //返回状态码 dump($res); } ~~~ ``` ``` ~~~ string(111399) " <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta name="renderer" content="webkit" /> <title>淘*网 - 淘!我喜欢</title> <meta name="spm-id" content="a21bo" /> ~~~ ``` ``` ~~~ public function cooka() { // $client = new \GuzzleHttp\Client(['cookies' => true]); $client = new \GuzzleHttp\Client(['base_uri' => 'https://www.tao*ao.com/']); $jar = new \GuzzleHttp\Cookie\CookieJar; $r = $client->request('GET', 'https://www.tao*ao.com/', [ 'cookies' => $jar ]); // $r = $client->request('GET', 'https://www.tao*ao.com'); dump($r); } ~~~ ``` ``` ~~~ object(GuzzleHttp\Psr7\Response)#67 (6) { ["reasonPhrase":"GuzzleHttp\Psr7\Response":private] => string(2) "OK" ["statusCode":"GuzzleHttp\Psr7\Response":private] => int(200) ["headers":"GuzzleHttp\Psr7\Response":private] => array(26) { ["Server"] => array(1) { [0] => string(7) "Tengine" } ["Content-Type"] => array(1) { [0] => string(24) "text/html; charset=utf-8" } ["Transfer-Encoding"] => array(1) { [0] => string(7) "chunked" } ["Connection"] => array(1) { [0] => string(10) "keep-alive" } ["Date"] => array(1) { [0] => string(29) "Sat, 25 Sep 2021 08:22:05 GMT" } ["Vary"] => array(2) { [0] => string(15) "Accept-Encoding" [1] => string(50) "Origin, Ali-Detector-Type, X-Host, Accept-Encoding" } ["x-server-id"] => array(1) { [0] => string(80) "28c3d6b2523ca52cb704b8b5dcd97677865cbbd91a3b0c7390a3a6f9f6babccc8bb00e660f25c2b1" } ["x-air-hostname"] => array(1) { [0] => string(31) "air-ual011087145003.center.na61" } ["x-air-trace-id"] => array(1) { [0] => string(26) "6f07ad0d16325581250005461e" } ["Cache-Control"] => array(1) { [0] => string(23) "max-age=0, s-maxage=109" } ["etag"] => array(1) { [0] => string(37) "W/"1b212-8CR+cNi3V6+Yp01zdJgFJgctuxg"" } ["x-readtime"] => array(1) { [0] => string(3) "221" } ["x-via"] => array(1) { [0] => string(93) "cn474.l1, cache3.cn474, l2nu16-1.l2, cache21.l2nu16-1, wormholesource011001084075.center.na61" } ["x-air-source"] => array(1) { [0] => string(5) "proxy" } ["x-xss-protection"] => array(1) { [0] => string(13) "1; mode=block" } ["EagleEye-TraceId"] => array(1) { [0] => string(26) "6f07ad0d16325581250005461e" } ["Strict-Transport-Security"] => array(1) { [0] => string(16) "max-age=31536000" } ["Timing-Allow-Origin"] => array(1) { [0] => string(4) "*, *" } ["Ali-Swift-Global-Savetime"] => array(1) { [0] => string(10) "1632558125" } ["Via"] => array(1) { [0] => string(106) "cache21.l2nu16-1[294,233,304-0,C], cache14.l2nu16-1[235,0], cache16.cn697[0,0,200-0,H], cache9.cn697[20,0]" } ["Age"] => array(1) { [0] => string(1) "3" } ["X-Cache"] => array(1) { [0] => string(26) "HIT TCP_MEM_HIT dirn:-2:-2" } ["X-Swift-SaveTime"] => array(1) { [0] => string(29) "Sat, 25 Sep 2021 08:22:05 GMT" } ["X-Swift-CacheTime"] => array(1) { [0] => string(3) "109" } ["x-air-pt"] => array(1) { [0] => string(3) "pt0" } ["EagleId"] => array(1) { [0] => string(26) "3da8641d16325581283392727e" } } ["headerNames":"GuzzleHttp\Psr7\Response":private] => array(26) { ["server"] => string(6) "Server" ["content-type"] => string(12) "Content-Type" ["transfer-encoding"] => string(17) "Transfer-Encoding" ["connection"] => string(10) "Connection" ["date"] => string(4) "Date" ["vary"] => string(4) "Vary" ["x-server-id"] => string(11) "x-server-id" ["x-air-hostname"] => string(14) "x-air-hostname" ["x-air-trace-id"] => string(14) "x-air-trace-id" ["cache-control"] => string(13) "Cache-Control" ["etag"] => string(4) "etag" ["x-readtime"] => string(10) "x-readtime" ["x-via"] => string(5) "x-via" ["x-air-source"] => string(12) "x-air-source" ["x-xss-protection"] => string(16) "x-xss-protection" ["eagleeye-traceid"] => string(16) "EagleEye-TraceId" ["strict-transport-security"] => string(25) "Strict-Transport-Security" ["timing-allow-origin"] => string(19) "Timing-Allow-Origin" ["ali-swift-global-savetime"] => string(25) "Ali-Swift-Global-Savetime" ["via"] => string(3) "Via" ["age"] => string(3) "Age" ["x-cache"] => string(7) "X-Cache" ["x-swift-savetime"] => string(16) "X-Swift-SaveTime" ["x-swift-cachetime"] => string(17) "X-Swift-CacheTime" ["x-air-pt"] => string(8) "x-air-pt" ["eagleid"] => string(7) "EagleId" } ["protocol":"GuzzleHttp\Psr7\Response":private] => string(3) "1.1" ["stream":"GuzzleHttp\Psr7\Response":private] => object(GuzzleHttp\Psr7\Stream)#65 (7) { ["stream":"GuzzleHttp\Psr7\Stream":private] => resource(118) of type (stream) ["size":"GuzzleHttp\Psr7\Stream":private] => NULL ["seekable":"GuzzleHttp\Psr7\Stream":private] => bool(true) ["readable":"GuzzleHttp\Psr7\Stream":private] => bool(true) ["writable":"GuzzleHttp\Psr7\Stream":private] => bool(true) ["uri":"GuzzleHttp\Psr7\Stream":private] => string(10) "php://temp" ["customMetadata":"GuzzleHttp\Psr7\Stream":private] => array(0) { } } } ~~~ ```