cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Output to terminal using libcurl

From: Lars Nilsson <chamaeleon_at_gmail.com>
Date: Thu, 17 Mar 2011 09:39:16 -0400

On Thu, Mar 17, 2011 at 9:14 AM, Ben Noordhuis <info_at_bnoordhuis.nl> wrote:
> On Thu, Mar 17, 2011 at 13:51, Oscar Salvador <pyscholeber_at_gmail.com> wrote:
>> Hi, how are you.
>> I have a doubt with libcurl. I'm retrieving an image from url, for
>> example: http://www.jejeje.com/pepe/52.jpg, 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?
>
> Set CURLOPT_FAILONERROR to 1. You won't have to do a separate 404
> check and your write function won't be called it if the HTTP status
> code >= 300.

Additional comment, if the function is supposed to be called multiple
times during the liftetime of the process (couldn't say since the code
is not a complete program..), you'd want to get rid of the global init
and cleanup in the function and put them at the start of the program
and before exiting. It is not supposed to be done for each transfer.

Lars Nilsson
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-03-17