<?php

function call_official_api($target_url, $raw)
{
  $curl = curl_init();

  curl_setopt_array($curl, array(
    CURLOPT_URL => "$target_url",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => false,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => "$raw",
    CURLOPT_HTTPHEADER => array(
      'authority: www.cartegrise.com',
      'pragma: no-cache',
      'cache-control: no-cache',
      'sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
      'accept: */*',
      'content-type: application/x-www-form-urlencoded; charset=UTF-8',
      'x-requested-with: XMLHttpRequest',
      'sec-ch-ua-mobile: ?0',
      'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
      'sec-ch-ua-platform: "macOS"',
      'origin: https://www.cartegrise.com',
      'sec-fetch-site: same-origin',
      'sec-fetch-mode: cors',
      'sec-fetch-dest: empty',
      'referer: https://www.cartegrise.com/france/demande-carte-grise-standard',
      'accept-language: en-US,en;q=0.9',
      'cookie: PHPSESSID=07v9kbmktkn26rn02v4jr11u22; _gid=GA1.2.1270545521.1643839750; _clck=19wkmmy|1|eyn|0; frontend=0cmfharqm5facf5744sp4e6719; _ga_YH4944P9W2=GS1.1.1643839749.60.1.1643840060.0; _ga=GA1.2.379313949.1633217440; _clsk=c5k0dr|1643840062663|5|1|a.clarity.ms/collect; _gat_UA-21906959-1=1; PHPSESSID=umap9h6pr310akvf39uogd7roi'
    ),
  ));

  $response = curl_exec($curl);

  curl_close($curl);
  return $response;
}
