0

I am having issues with CURL response. Whenever I try to carry out a curl request, I am getting response in none readable format.

�)K���m!`׽����]mO�@������1���g��^�ګ�6���?]8�"wP�����gf��E�)��`�fgg�ea�1{�:���k�����ŰVC��/�2���\��sA�:��<i��f��я�n�5כY�Y������Ƀ�%��X� �[&9��P\A��pk9-��Uw��2|t���~�V��fYjC��!u���R�5��w��);եЕ4�����YDe�+T�w��I�� /l�>�S�I�/Ɯm@�`d]1��@�`

Below I have provided my code:

$header = array();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] =  "Cache-Control: max-age=0";
$header[] =  "Connection: keep-alive";
$header[] = "Keep-Alive: 3000";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.
curl_setopt(self::$curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7');
curl_setopt(self::$curl, CURLOPT_HTTPHEADER, $header);

curl_setopt(self::$curl,CURLOPT_COOKIEJAR, $cookieJar);
curl_setopt(self::$curl,CURLOPT_COOKIEFILE, $cookieJar);

curl_setopt(self::$curl,CURLOPT_AUTOREFERER, true);
curl_setopt(self::$curl,CURLOPT_FOLLOWLOCATION, true);
curl_setopt(self::$curl,CURLOPT_RETURNTRANSFER, true);

curl_setopt(self::$curl,CURLOPT_SSL_VERIFYPEER, false);

The website I am trying to scrape is https://www.boots.com/

When I try on other website (e.g. https://www.bbc.co.uk/news), it works fine.

If there's anything more to be added in please ask.

Thanks

Barmar
  • 741,623
  • 53
  • 500
  • 612
dark_illusion_909099
  • 1,067
  • 2
  • 21
  • 41

1 Answers1

0

I have added these additional headers at the start which fixed the issue for me.

        $header[0] = "Access-Control-Allow-Origin: *,";
        $header[0] .= "Access-Control-Expose-Headers: Content-Length, X-JSON,";
        $header[0] .= "Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS,";
        $header[0] .= "Access-Control-Allow-Headers: *,";
dark_illusion_909099
  • 1,067
  • 2
  • 21
  • 41