Convert Acquia Clear Varnish For One URL Curl Command to Drupal::httpClient() I am trying to convert a command to php curl or Drupal::httpClient().
The original command
Curl -k -X PURGE -H &quot;X-Acquia-Purge:[site-name]&quot; --compressed -H &quot;Host: example.com&quot; https://bal-12345.prod.hosting.acquia.com/my-url

Here is the conversion I tried (but it is not working) This one returns 200 status code but it is not working.
$varnishUrl = &quot;https://bal-12345.prod.hosting.acquia.com/my-url&quot;
$headers = [
  'X-Acquia-Purge'  =&gt; &quot;site-name&quot;,
  'Host'            =&gt; &quot;example.com&quot;
];
$options = ['headers' =&gt; $headers, 'body' =&gt; $varnishUrl];
try {
  $client = \Drupal::httpClient();
  $response = $client-&gt;request('PURGE', $domainUrl, $options);
  $code = $response-&gt;getStatusCode();
  if ($code == 200) {
    return $code;
  }
}
catch (RequestException $e) {
  watchdog_exception('module_name', $e);
}

This is the second conversion to php and also not working.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $varnishUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PURGE');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'X-Acquia-Purge: site-name';
$headers[] = 'Host: example.com';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_exec($ch);
curl_close($ch);

I would appreciate any input.
I found the solution: https://docs.acquia.com/cloud-platform/performance/varnish/manually-purge/#manually-clearing-caches-for-applications-using-ssl
PHP way:
    $varnishUrl = 'https://bal-' . $elbDomain . '.prod.hosting.acquia.com' . $nodeUrl;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $varnishUrl);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PURGE');
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    $headers = [];
    $headers[] = &quot;X-Acquia-Purge: {$xAcquiaPurge}&quot;;
    $headers[] = &quot;Host: example.com&quot;;
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_exec($curl);
    $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ($code == 200) {
      return $code;
      curl_close($curl);
    }
    $errorMsg = curl_getinfo($curl);
    \Drupal::logger('module_name')-&gt;error(json_encode($errorMsg));
    curl_close($curl);

Drupal way:
    $varnishUrl = 'https://bal-' . $elbDomain . '.prod.hosting.acquia.com' . $nodeUrl;
    $options = [
         'verify' =&gt; false,
         'headers' =&gt; [
           'X-Acquia-Purge' =&gt; $xAcquiaPurge,
           'Host' =&gt; 'example.com',
         ],
       ];
       try {
         $client = \Drupal::httpClient();
         $response = $client-&gt;request('PURGE', $varnishUrl, $options);
         $code = $response-&gt;getStatusCode();
         if ($code == 200) {
           return $code;
         }
       }
       catch (RequestException $e) {
         watchdog_exception('module_name', $e);
       }