title: PHP read HTTP/2 response Body
body: <p>I want to read HTTP/2 response in php.</p>
  <p>Below is the code I have.</p>
  <pre><code>     $ch = curl_init();
          curl_setopt_array($ch, [
          CURLOPT_URL            =&gt;$url,
          CURLOPT_HEADER         =&gt;1,
          CURLOPT_CUSTOMREQUEST  =&gt;'GET',
          CURLOPT_RETURNTRANSFER =&gt;true,
          CURLOPT_HTTP_VERSION   =&gt;CURL_HTTP_VERSION_2_0,
          CURLOPT_HTTPHEADER     =&gt;$headers,
          CURLOPT_PROXY          =&gt;$proxy,
          CURLOPT_SSL_VERIFYPEER =&gt;False,
          CURLOPT_COOKIE         =&gt;$sessionCookie,
          CURLOPT_VERBOSE         =&gt;0,
      ]);
      $response = curl_exec($ch);
      $curl_info = curl_getinfo($ch);
      curl_close($ch);
  
      $header_size = $curl_info['header_size'];
      $download_content_length = $curl_info['size_download'];
      
      $headers = substr($response, 0, $header_size);
      $body = substr($response, $header_size, $download_content_length);
      $jsondata = json_decode($body,TRUE);
  </code></pre>
  <p>Notice that when I send the request through Proxy(Burp,ZAP) I am able to read the response. But, when I disable the proxy. I am unable to read the response body.</p>
  <p>Below is the error I get:</p>
  <pre><code>Exception: Trying to access array offset on value of type null in test.php:77
  </code></pre>
  <p>where Line 77 is the last line from the above code.</p>
  <p>Below is the <em>var_dump</em> of the <code>$response</code>:</p>
  <pre><code>HTTP/2 200
  date: Mon, 21 Jun 2021 15:38:44 GMT
  content-type: application/json; charset=utf-8
  content-length: 788
  content-encoding: gzip
  x-frame-options: SAMEORIGIN
  x-xss-protection: 1; mode=block
  x-content-type-options: nosniff
  strict-transport-security: max-age=15552000; includeSubDomains; preload
  referrer-policy: origin
  permissions-policy: geolocation=(self), microphone=(), camera=()
  content-security-policy: default-src 'self' 'unsafe-inline' 'unsafe-eval' wss: https:; img-src 'self' data: https:; style-src 'self' 'unsafe-inline' https:;
  
  ���Ooƿ
  �¼�3��zʩ�)����Ĩj����\r-K#��3��C�G�pz8�=�|&lt;-�r~��?��eW&gt;���O�e�������&gt;����Z�����P��?��2����l��h�*&amp;�G�
  a�*fVˮ�;��n@5tea�
  </code></pre>
  <p>It is in unreadable format. How can i read them?</p>