RE: POST with HEAD?

"Liu Shan Shui" <[email protected]>
Newsgroups gmane.comp.web.curl.php
Message-ID <001f01ca1736$f1cfca00$d56f5e00$@sg>
Hi Daniel,

Thanks for your input. I did a little bit of Googling after you mentioned
callbacks, and found this:
http://sg.php.net/manual/en/function.curl-setopt.php#73742

Then I came up with the following code, which executes within a few seconds
(thereby showing that it didn't download the 1000 MB file):

<?php

$c = curl_init();
curl_setopt($c, CURLOPT_URL,
'http://speedtest.bbned.nl/download/file1000mb.bin');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HEADER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, 'a=b&c=d');
curl_setopt($c, CURLOPT_WRITEFUNCTION, create_function('$c, $s', '')); 
curl_exec($c);

header('Content-Type: text/plain');
var_dump(curl_getinfo($c));

?>

A few notes here: Curl_exec($c) returns FALSE probably because there's no
output, but the HTTP request is still sent accordingly. Setting
CURLOPT_HEADER to TRUE seems to make cURL to ignore even the response
headers (header_size becomes 0), and I'm guessing that it's because the
header output is handled by CURLOPT_WRITEFUNCTION together with the response
body instead of CURLOPT_HEADERFUNCTION.

With regards,
Liu Shan Shui
[email protected]
"Life would be much easier if I had the source code." - Anonymous

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Daniel Stenberg
Sent: Friday, August 07, 2009 2:59 PM
To: curl with PHP
Subject: Re: POST with HEAD?

On Fri, 7 Aug 2009, Stephen Pynenburg wrote:

> I encountered this behaviour a while ago - not sure why, but it seems
you're 
> correct in saying that CURLOPT_POST and _NOBODY don't go together well.
The 
> solution that worked for me was very simple: just use curl_setopt($ch, 
> CURLOPT_CUSTOMREQUEST, "POST") instead of setting CURLOPT_POST.

Let me just warn you when doing this.

The NOBODY option implies a HEAD request when you do it with HTTP. A HEAD 
request MUST NOT have a response body and thus libcurl will not read any
such.

A POST response almost always have a body, and you can tell libcurl to abort

the reading of that by returning something appropriate from a callback or 
similar.

By using NOBODY but setting CUSTOMREQUEST to "POST", you're basically
telling 
libcurl to do a HEAD but to replace the method name. This may work fine, but

you should then remember that libcurl will still internally work as if it is

indeed a HEAD request.

-- 

  / daniel.haxx.se
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.