I want to read HTTP/2 response in php.
Below is the code I have.
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL =>$url,
CURLOPT_HEADER =>1,
CURLOPT_CUSTOMREQUEST =>'GET',
CURLOPT_RETURNTRANSFER =>true,
CURLOPT_HTTP_VERSION =>CURL_HTTP_VERSION_2_0,
CURLOPT_HTTPHEADER =>$headers,
CURLOPT_PROXY =>$proxy,
CURLOPT_SSL_VERIFYPEER =>False,
CURLOPT_COOKIE =>$sessionCookie,
CURLOPT_VERBOSE =>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);
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.
Below is the error I get:
Exception: Trying to access array offset on value of type null in test.php:77
where Line 77 is the last line from the above code.
Below is the var_dump of the $response
:
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�=�|<-�r~��?��eW>���O�e�������>����Z�����P��?��2����l��h�*&�G�
a�*fVˮ�;��n@5tea�
It is in unreadable format. How can i read them?