cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl: how to discard response data from an upload?

From: Apurva Mehta <apurva_at_mathmeth.com>
Date: Tue, 17 Feb 2009 11:08:58 -0800

Hi,

   I want to to use libcurl to upload a file using the HTTP PUT
method. I am interested in the response headers, but don't want to
deal with the response data. So I decided to redirect the response
data to /dev/null. Here are the curl options I am using to achieve
this behavior.

    CURL *chandle = curl_easy_init();

    string url = "some url";
    FILE *dev_null = fopen ("/dev/null" , "w+");

    if (dev_null == NULL) {
        perror ("Could not open /dev/null for writing");
        return -1;
    }

    curl_easy_setopt (chandle, CURLOPT_URL, url.c_str());
    curl_easy_setopt (chandle , CURLOPT_NOPROGRESS , 1 ) ;

    curl_easy_setopt (chandle , CURLOPT_UPLOAD, 1L) ;
            
    curl_easy_setopt (chandle, CURLOPT_HEADERDATA, (void *)
shared_data );
    curl_easy_setopt (chandle, CURLOPT_HEADERFUNCTION,
upload_header_callback);
        
    curl_easy_setopt (chandle, CURLOPT_WRITEDATA, dev_null);

    curl_easy_setopt (chandle, CURLOPT_READDATA, (void *) shared_data);
    curl_easy_setopt (chandle, CURLOPT_READFUNCTION, read_callback);
    curl_easy_setopt (chandle, CURLOPT_INFILESIZE_LARGE, shared_data-
>upload_size);

* * *

   The upload works fine, and I can process the response headers as I
desire. However, the response data still gets written to stdout. Is
there something I am missing? What else can I do to prevent the
response data from being written to stdout?

Thanks,
Apurva
Received on 2009-02-17