cURL / Mailing Lists / curl-users / Single Mail

curl-users

POST to GET question

From: Andrey Ivanov <andrey_at_infoart.com.ua>
Date: Mon, 11 Jun 2007 10:50:46 +0300

Hello.

I've noticed a strange curl behaviour, the whole thing works in most
cases but this is odd anyway. The problem appears when I'm trying to
make a GET request just after I make POST using the same handle. Here is
slightly modified curl/docs/examples/debug.c:

   curl = curl_easy_init();
   if(curl) {
     curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
     curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);

     /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

     curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
     curl_easy_setopt(curl, CURLOPT_POST, 1);
     curl_easy_setopt(curl, CURLOPT_HTTPPOST, 0);
     curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "a=b&c=d");

     /* make POST */
     res = curl_easy_perform(curl);

     curl_easy_setopt(curl, CURLOPT_POST, 0);
     /* just to be sure */
     curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
     /* make GET */
     res = curl_easy_perform(curl);

     /* always cleanup */
     curl_easy_cleanup(curl);
   }

This code is supposed to make two HTTP requests (am I right?) first POST
and then GET. And this is what I see in debug output:

request 1:

== Info: About to connect() to example.com port 80
== Info: Trying 208.77.188.166... == Info: connected
== Info: Connected to example.com (208.77.188.166) port 80
=> Send header, 144 bytes (0x90)
0000: POST / HTTP/1.1
0011: Host: example.com
0024: Pragma: no-cache
0036: Accept: */*
0043: Content-Length: 7
0056: Content-Type: application/x-www-form-urlencoded
0087:
0089: a=b&c=d
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK

request 2:

== Info: Closing connection #0
== Info: About to connect() to example.com port 80
== Info: Trying 208.77.188.166... == Info: connected
== Info: Connected to example.com (208.77.188.166) port 80
=> Send header, 137 bytes (0x89)
0000: POST / HTTP/1.1
0011: Host: example.com
0024: Pragma: no-cache
0036: Accept: */*
0043: Content-Length: 0
0056: Content-Type: application/x-www-form-urlencoded
0087:
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK

As you can see, it's POST type request too and it even contains
Content-Type: application/x-www-form-urlencoded header. My curent
workaround is making curl_easy_cleanup() ... curl_easy_init() for each
request, but I don't think this is the way it is supposed to work,
because the docs say "You can do any amount of calls to
curl_easy_perform(3) while using the same handle." Please tell me if
it's a bug or some kind of misunderstanding.
Received on 2007-06-11