title: Using Auth Digest header variable in PHP curl request
body: <p>I am working with an API that provides a token for me to use to connect. It gives these instructions.</p>
  
  <p>This token is then sent in all subsequent calls to the server in header variable Auth Digest.</p>
  
  <p>I am not sure what this means. I've tried several approaches and read several stack overflow questions. Here's what I've tried. See code comments included for details.</p>
  
  <pre><code>$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_FAILONERROR, true);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
  curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  curl_setopt($ch, CURLOPT_VERBOSE, true);
  
  // I have tried setting both of these
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
  
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  
  // In combination of the above separately, I have tried each of these individually
  curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $token);
  
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Auth Digest: ' . $token));
  
  curl_setopt($ch, CURLOPT_POST, true);
  $post_data = array('Auth Digest' =&gt; $token);
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  
  curl_setopt($ch, CURLOPT_USERPWD, $token); 
  
  // Then I execute and close, either giving me a failed response and a response that says token is not valid
  $response = curl_exec($ch);
  $header_sent = curl_getinfo($ch, CURLINFO_HEADER_OUT);
  if (!$response) {
      echo $action . ' curl request failed';
      return false;
  }
  curl_close($ch);
  $response_json = json_decode($response);
  var_dump($response_json);
  </code></pre>
  
  <p>Here are some related stackoverflow questions that I've tried to apply to my problem without success.</p>
  
  <p><a href="https://stackoverflow.com/questions/10319403/curl-request-with-digest-auth-in-php-for-download-bitbucket-private-repository">Curl request with digest auth in PHP for download Bitbucket private repository</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18664957/client-part-of-the-digest-authentication-using-php-post-to-web-service">Client part of the Digest Authentication using PHP POST to Web Service</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2140419/how-do-i-make-a-request-using-http-basic-authentication-with-php-curl">How do I make a request using HTTP basic authentication with PHP curl?</a></p>
  
  <p>I need to know what the raw http header that they're likely expecting or how I can use php curl to generate the header they're likely expecting.</p>