cURL / Mailing Lists / curl-library / Single Mail

curl-library

Documentation on how to do a zero-byte POST is misleading

From: McGarvey, Kevin <kmcGarvey_at_verisign.com>
Date: Tue, 20 Nov 2007 13:36:54 -0500

The API documentation describes how to do a zero-byte post, as follows:

"If you want to do a zero-byte POST, you need to set
CURLOPT_POSTFIELDSIZE explicitly to zero, as simply setting
CURLOPT_POSTFIELDS to NULL or "" just effectively disables the sending
of the specified string. libcurl will instead assume that you'll send
the POST data using the read callback!"

This is misleading, in that it implies that setting CURLOPT_POSTFIELDS
to NULL is OK and equivalent to setting it to "", as long as you set
CURLOPT_POSTFIELDSIZE explicitly to zero. This is not the case.
Setting CURLOPT_POSTFIELDS to NULL causes the subsequent post request to
block, even if CURLOPT_POSTFIELDSIZE is explicitly set to zero. However
explicitly setting CURLOPT_POSTFIELDSIZE to zero and setting
CURLOPT_POSTFIELDS to "" works fine.

In other words, this works:

    curl_rc = curl_easy_setopt(clntPtr_, CURLOPT_POSTFIELDSIZE, 0);
    curl_rc = curl_easy_setopt(clntPtr_, CURLOPT_POSTFIELDS, "");

but this doesn't:

    curl_rc = curl_easy_setopt(clntPtr_, CURLOPT_POSTFIELDSIZE, 0);
    curl_rc = curl_easy_setopt(clntPtr_, CURLOPT_POSTFIELDS, NULL);

Please update the API documentation, or better yet, treat NULL the same
as "" when CURLOPT_POSTFIELDSIZE has been explicitly set to 0.

Thanks,

Kevin McGarvey
Principal Software Engineer
VeriSign, Inc.
Received on 2007-11-20