cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Endless waiting on POST with zero content length

From: Emil Romanus <sdac.bithack_at_gmail.com>
Date: Tue, 31 Jul 2007 20:07:27 +0200

2007/7/6, Daniel Stenberg <daniel_at_haxx.se>:
>
>
> I can't find any libcurl docs anywhere that says setting
> CURLOPT_POSTFIELDS to
> NULL is a good idea for any purpose.

[...]

Since you didn't show us a complete example, I have trouble to see how this
> is
> a bug in libcurl or if so, what the exact problem might be.
>
>
You are right, I was probably using libcurl wrong.

On a second thought, I'd like to go through this and work out if it really
might be a bug or just bad usage from my side.

Let me quote the libcurl tutorial:
"Just setting CURLOPT_POSTFIELDS to "" or NULL will *not* stop libcurl from
doing a POST. It will just make it POST without any data to send!"

That is what I tīred, setting it to NULL to perform an empty POST request.
However, as I described libcurl hangs. I added a little test program below,
however I am not sure how you want me to attach it, so I'll just copy it
into this email. It's pretty short anyway.

#include <curl/curl.h>

int main(void)
{
    curl_global_init(0);
    CURL *h = curl_easy_init();
    const char *post = "test=hej;coffee=yummie";
    curl_easy_setopt(h, CURLOPT_POSTFIELDS, post);
    curl_easy_setopt(h, CURLOPT_URL, "http://google.com/");
    curl_easy_perform(h);

    /* second transfer, want it to be an empty POST */
    curl_easy_setopt(h, CURLOPT_POSTFIELDS, 0);
    /* uncomment line below to make the code work as expected, meaning it
has something to do with internal data length still set from last request */
    /* curl_easy_setopt(h, CURLOPT_POSTFIELDSIZE, 0); */
    curl_easy_perform(h);
    curl_easy_cleanup(h);
    return 0;
}
Received on 2007-07-31