PHP cURL: get headers only from post

Posted by Stewart on Stack Overflow See other posts from Stack Overflow or by Stewart
Published on 2010-12-12T02:22:45Z Indexed on 2010/12/26 0:54 UTC
Read the original article Hit count: 179

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about curl