cURL / Mailing Lists / curl-library / Single Mail

curl-library

HTTP POST: howto get just the the response content?

From: svante karlsson <saka_at_csi.se>
Date: Sat, 2 Apr 2011 18:45:02 +0200

I'm new to libcurl so this might be obvious...

If I do a HTTP get with a
....
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, write_callback_std_stream);
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, ostream);
....
then my callback "write_callback_std_stream" gets called with the
content of the request.

but when I try to do a HTTP POST my request content ends up correctly
at the server which the responds with content (a binary file)

however using the same construct as above

 ....
        curl_easy_setopt (_curl, CURLOPT_URL,url.c_str());
        curl_easy_setopt (_curl, CURLOPT_POST, 1);

        /* the transmitted content */
        curl_easy_setopt (_curl, CURLOPT_POSTFIELDSIZE_LARGE ,
(curl_off_t) content_lenght); // must be different in post and put???
        /* we want to use our own read function */
        curl_easy_setopt(_curl, CURLOPT_READFUNCTION, read_callback_std_stream);
        /* now specify which file to upload */
        curl_easy_setopt(_curl, CURLOPT_READDATA, istream);

        /* the reply */
        curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION,
write_callback_std_stream);
        curl_easy_setopt(_curl, CURLOPT_WRITEDATA, ostream);

        struct curl_slist *headerlist=NULL;
        static const char buf[] = "Expect:";
        /* initalize custom header list (stating that Expect:
100-continue is not wanted */
        headerlist = curl_slist_append(headerlist, buf);
        curl_easy_setopt(_curl, CURLOPT_HTTPHEADER, headerlist);

        CURLcode res = curl_easy_perform(_curl);
...

my callback gets called first with each response header then with the
(my) desired content - while the headers are interesting is there a
way of getting rid of those before the callback?

Is there a better way of doing this or should I resort to parsing away
the headers before storing the content?

regards
svante
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-04-02