title: How to get info on sent PHP curl request
body: <p>I'm trying to debug a curl request to a webservice 'getToken' endpoint. </p>
  
  <p>I'm not 100% confident that the URL and the auth info is getting written in to the curl handle correctly. </p>
  
  <p>I'm trying to use <code>curl_getinfo($ch, CURLINFO_HEADER_OUT);</code> to capture the sent request, but it doesn't give me much info. Is there a way to get more in depth diagnostics about what the actual curl request looks like?</p>
  
  <p>Here's the code:</p>
  
  <pre><code>$ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");       
  curl_setopt($ch, CURLOPT_HEADER, 1); // just getting header to see if we got an auth token
  curl_setopt($ch, CURLOPT_FILE, $fh);
  curl_setopt($ch, CURLOPT_NOBODY, 1); 
  curl_setopt($ch, CURLINFO_HEADER_OUT, 1); // capture the header info
  curl_setopt($ch, CURLOPT_VERBOSE, 1); // turn verbose on    
  // execute the curl request 
  
  $rh = fopen("request.txt", "w"); // open request file handle
  $verbose = fopen('php://temp', 'rw+');
  curl_setopt($ch, CURLOPT_STDERR, $verbose);
  
  curl_exec($ch); // execute request
  
  $sent_request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
  fwrite($rh, $sent_request); // save the request info
  fclose($rh);
  !rewind($verbose);
  $verboseLog = stream_get_contents($verbose);
  
  echo "Verbose information:\n&lt;pre&gt;", htmlspecialchars($verboseLog), "&lt;/pre&gt;\n";
  </code></pre>
  
  <p>This all works as far as it goes, but returns a 401 every time-- the API admin assures me that the username / pass I have is correct. </p>
  
  <p>I was wondering if I'm somehow getting the URL value wrong, or not sending the right username / pass, but this info isn't printed in the request data saved:</p>
  
  <pre><code>HEAD /export/auth HTTP/1.1
  Authorization: Basic Y2FpcmRzdW5mYTpENWlAaVM4cw==
  Host: webservices.mycompany.com
  Accept: */*
  </code></pre>
  
  <p>You can see that the username/pass is not recorded (I assume for security). The endpoint URL  I think is the <code>host</code> value plus the start of the <code>HEAD</code> value, so <code>webservices.mycompany.com/export/auth</code>?</p>
  
  <p>The "Verbose Information" statement prints nothing. Not sure why on this either!</p>
  
  <p>Thanks for help.</p>
  
  <p>EDIT: added verbose mode from <a href="https://stackoverflow.com/questions/3757071/php-debugging-curl">Php - Debugging Curl</a> thanks to commenter immulatin</p>