cURL / Mailing Lists / curl-library / Single Mail


Output to terminal using libcurl

From: Oscar Salvador <>
Date: Thu, 17 Mar 2011 13:51:31 +0100

Hi, how are you.
I have a doubt with libcurl. I'm retrieving an image from url, for
example:, and i save this in a
memory buffer. This works correctly.
Before retrieve the image, I check if image exists or no with:

[[ curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code); ]]

If http_code contains "404", i close libcurl and return to he previous
function, but when i call curl_perform to see if image exists, i get
the output to the terminal.
Is there any solution for don't send to terminal?

The code is:

char *get_image(unsigned int id_photo)
        char url[64];
        CURL *curl_handle;
         struct MemoryStruct chunk;
        long http_code;

                chunk.memory = malloc(1);
                chunk.size = 0;

                snprintf( url, sizeof(url)-1,
"", id_photo);
                printf("URL-> [%s]\n", url);


                    curl_handle = curl_easy_init();

                    curl_easy_setopt(curl_handle, CURLOPT_URL, url);


                curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code);
                if(http_code != HTTP_OK) {
                        return NULL;

                  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeinbuffer);

                  curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);

                   curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");



                FILE *file = fopen("image.jpg", "wb");
                fwrite(chunk.memory, 1, chunk.size, file);
                  return chunk.memory;

Thanks a lot,

List admin:
Received on 2011-03-17