J
J
jugger12021-01-24 20:27:55
PHP
jugger1, 2021-01-24 20:27:55

How to make it so that the response of a curl request comes in the form of html, and not json?

I send a curl request, and the response is a json file with a large number of arrays, which is difficult to parse. How to make it so that the response would come as an html page?

$ch = curl_init();
  
        curl_setopt($ch, CURLOPT_URL, 'тут указал сайт');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "тут указал json");
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

        $headers = array();
        $headers[] = 'Authority: тут сайт';
        $headers[] = 'X-Calledmethod: Event.Get';
        $headers[] = 'X-Lastmodification: 2021-01-20T175611.534664+03';
        $headers[] = 'Accept-Language: ru-RU;q=0.8,en-US;q=0.5,en;q=0.3';
        $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36';
        $headers[] = 'Content-Type: application/json; charset=UTF-8';
        $headers[] = 'Accept: application/json, text/javascript, */*; q=0.01';
        $headers[] = 'X-Requested-With: XMLHttpRequest';
        $headers[] = 'X-Originalmethodname: RXZlbnQuR2V0';
        $headers[] = 'Origin: www.example ';
        $headers[] = 'Sec-Fetch-Site: same-origin';
        $headers[] = 'Sec-Fetch-Mode: cors';
        $headers[] = 'Sec-Fetch-Dest: empty';
        $headers[] = 'Referer: тут указал сайт';
        $headers[] = 'Cookie:тут куки"';
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close($ch);
        return $result;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-01-24
@jugger1

No, if the site does not support the return of html.
If it does, then it already depends on the site itself - it can be implemented in any way there. You can start by specifying the correct title Accept.
The statement "it's hard for me to parse JSON, so I want to parse HTML" is very, very strange, because it's much easier to work with JSON. Unless, of course, you do not form this HTML yourself (but then what does it have to do with "parsing"?).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question