PHP cURL: get headers only from post
- by Stewart
There ought to be a way of sending a post request and getting back just the headers.
$ch = curl_init('http://www.stackoverflow.com/');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
doesn't work, because all setting CURLOPT_NOBODY does is to change the request method to HEAD, thereby overriding CURLOPT_POST.
I could just leave the last of these lines out and only process the headers, but is there a more efficient way?
It's also odd that there doesn't seem to be a way in cURL to truncate the received content to a specified length as there is with file_get_contents.