Для Curl:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);

Для Guzzle:

use GuzzleHttp\Client;

$client = new Client();
$client->get('https://google.com/', [
    'version' => 2.0,
    'debug' => true,
]);

Благодаря опции debug можно будет увидеть отладочную информацию и убедиться, что всё работает как и задумано:

* Rebuilt URL to: https://www.google.com/
*   Trying 216.58.201.3...
* Connected to www.google.com (216.58.201.3) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /usr/local/etc/openssl/cert.pem
  CApath: none
* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.google.com
*  start date: Aug 17 18:56:43 2016 GMT
*  expire date: Nov  9 18:29:00 2016 GMT
*  subjectAltName: host "www.google.com" matched cert's "*.google.com"
*  issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* TCP_NODELAY set
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fa804802000)
> GET / HTTP/1.1
Host: www.google.com
User-Agent: GuzzleHttp/6.2.1 curl/7.50.1 PHP/7.0.10
 
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200
< date: Sun, 28 Aug 2016 10:36:13 GMT
< expires: -1
< cache-control: private, max-age=0
< content-type: text/html; charset=ISO-8859-1
< p3p: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."
< server: gws
< x-xss-protection: 1; mode=block
< x-frame-options: SAMEORIGIN
< set-cookie: NID=85=UrPdiR04M5ZzIUtj4sZMPRZbY8vZEKVvazZy59PpoO5NG29lVX7JNuaeiajLhDKHiEBF2tWev3yj0xFF7fvYChmARVsFSnfiBX06ewWnMaPeXy0KkneQJ7dmHGS7JYaz; expires=Mon, 27-Feb-2017 10:36:13 GMT; path=/; domain=.google.com; HttpOnly
< alternate-protocol: 443:quic
< alt-svc: quic=":443"; ma=2592000; v="35,34,33,32,31,30"
< accept-ranges: none
< vary: Accept-Encoding
<
* Connection #0 to host www.google.com left intact

 
			

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *

Любишь мемасики?

Подпишись на мой телеграм-канал!

Открыть
Закрыть