-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?

4
  • Does this answer your question? How to properly handle a gzipped page when using curl? Commented May 1, 2020 at 19:07
  • How can I use '--compressed' flag in my php cURL lib? Commented May 1, 2020 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 Commented May 2, 2020 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 ? Commented May 3, 2020 at 20:34

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

2 Comments

$html = htmlspecialchars($data); // returns ''
Include the image in the post. So we can see it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.