-1

I'm trying to get simple html code, from cURL GET-request on PHP.
Default get-request on url, like http://example.com/ (not exacly this domain), returns html code I need, but get-request on page of this domain, like http://example.com/something returns gzip encrypted data, or something.
What I already tried to fix this issue:

curl_setopt(ch, CURLOPT_ENCODING, ''); // returns ''
curl_setopt(ch, CURLOPT_ENCODING, 'gzip'); // returns ''
curl_setopt(ch, CURLOPT_ENCODING, 'gzip,compressed'); // returns ''
$html = gzdecode($data); // data error

By the way, on inspector, like Fiddler, this page returns similar wierd symbols, but it fixes by one click: 'Click to decrypt'. How I can decrypt my data programmatically, using PHP?

  • Does this answer your question? [How to properly handle a gzipped page when using curl?](https://stackoverflow.com/questions/8364640/how-to-properly-handle-a-gzipped-page-when-using-curl) – William Prigol Lopes May 01 '20 at 19:07
  • How can I use '--compressed' flag in my php cURL lib? – Binary Bear May 01 '20 at 19:24
  • from the **terminal** run `$ curl -o response.txt -D header.txt http://example.com/something` - (this will get the page and save the response's header into `header.txt`) - then update your question adding the response's header. It may be useful to find out how the response is compressed/encoded – Paolo May 02 '20 at 19:31
  • i'm not aware of any `click to decrypt` button in Fiddler - there is a `Click to decode`-button, though, do you mean `Click to decode` ? – hanshenrik May 03 '20 at 20:34

1 Answers1

-2

If I understood you well, you need to get the content in HTML from an url.

Please, check this link: Get HTML from URL using curl in PHP

You don't need to use CURLOPT_ENCODING in curl_setopt.

EDIT

I tried this and it works:

<?php
function get_data($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$html_content = get_data('https://stackoverflow.com/questions/61548866/php-curl-returns-encrypted-html-page/61549219?noredirect=1#comment108875034_61549219');

echo "You are getting HTML code from an url <br>".$html_content;
?>

Image with test working in localhost

Thank you, I hope it helps you.

Salvation
  • 21
  • 4