cURL / Mailing Lists / curl-library / Single Mail


Issue With curl_easy_perform

From: Saikat Kanjilal <>
Date: Fri, 31 Mar 2006 16:39:27 -0800

Hello All:
I am trying to use libcurl to do a simple http_post, I have the code below,
everything works like a charm except that curl_easy_perform keeps popping up
this window, I have a callback function that I have written using
CURLOPT_WRITEFUNCTION but that still does not make the dos window completely
go away, any help on this would be much appreciated. I have been struggling
with this for a day or so, any ideas??

/* libcurl callback function */
extern "C" size_t write_data(void *source ,size_t size ,size_t nmemb ,void

extern "C" size_t write_data(void *source ,size_t size ,size_t nmemb ,void
        size_t retval=0;
        std::cout<<"Inside write_data\n";
        return retval;

int MyClass::uploadFile(std::string URL,std::string path)
        CURL *curl;
    CURLcode res;

    struct curl_httppost *formpost=NULL;
    struct curl_httppost *lastptr=NULL;
    struct curl_slist *headerlist=NULL;
    char buf[] = "Expect:";
        bool delFile = false;


    /* Fill in the file upload field */
                 CURLFORM_COPYNAME, "sendfile",
                                 CURLFORM_FILE, path.c_str(),

    /* Fill in the filename field */
                 CURLFORM_COPYNAME, "filename",
                                 CURLFORM_COPYCONTENTS, path.c_str(),

    /* Fill in the submit field too, even if this is rarely needed */
                 CURLFORM_COPYNAME, "submit",
                 CURLFORM_COPYCONTENTS, "send",

    curl = curl_easy_init();

        /* initalize custom header list (stating that Expect: 100-continue is not
       wanted */
    headerlist = curl_slist_append(headerlist, buf);

        /* if we have a handle proceed with the transaction */
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);

                /* what URL that receives this POST */
                curl_easy_setopt(curl, CURLOPT_URL, URL.c_str());
                curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
                res = curl_easy_perform(curl);

                /* if the file was transported successfully we need to delete
                   the file else wait a while and try to upload
                if (res==CURLE_OK)
                        /* if we are here we wait
                           and try the upload again till we are successful
                           for now we set this to 2 minutes
                           later it will be configurable

                /* cleanup */

           /* then cleanup the formpost chain */

           /* free slist */
           curl_slist_free_all (headerlist);

        if (delFile)
        return res;

Thanks Again
Received on 2006-04-01