tags:

views:

57

answers:

1

For instance, on the following CURL snippet:

  $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url); //set target URL
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);// allow redirects
    curl_setopt($ch, CURLOPT_POST, $usePost); // set POST method
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //set headers
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, $returnHeaders); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //prevent unverified SSL error

Before I run curl_exec on it, what if I want to see the full request headers and body before it is sent. (to see if is correctly following certain REST API guidelines)

+1  A: 

You could send a request to the local server:

$test_url = 'http://localhost/nonexistent-page';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $test_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
// Other options.
curl_exec($ch);

echo nl2br(curl_getinfo($ch, CURLINFO_HEADER_OUT));

This will give you the request headers, with only the request line path and the Host: line being different from your actual request.

GZipp