cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Output to terminal using libcurl

From: Oscar Salvador <pyscholeber_at_gmail.com>
Date: Thu, 17 Mar 2011 16:18:52 +0100

2011/3/17 Lars Nilsson <chamaeleon_at_gmail.com>:
> 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
>

Thanks to both for answer my question.
It works fine.

Regards ;_)

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