cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Download a gif

From: Michael Hecker <Hecker.Michael_at_gmx.de>
Date: Fri, 15 Feb 2008 10:51:42 +0100

Jeff Pohlmeyer schrieb:
> On Fri, Feb 15, 2008 at 3:28 AM, Michael Hecker <Hecker.Michael_at_gmx.de> wrote:
>
>> Thats right.
>> How can I print all the data?
>>
>
> Please don't top-post.
>
> I suspect you want fwrite() and not fprintf()
>
> - Jeff
>
>

Part1:
bool Cxyz::communicate3()
{
    // Rahmeninformationen der Kommunikation
    curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(curl_handle, CURLOPT_DEBUGFUNCTION, my_trace);
       
    // Klasse soll alle Daten an WriteMemoryCallback senden
    curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION,
WriteMemoryCallback3);
    // Über gabe des "chunk" structs an die Callback-Funktion
    CCommunicator_MemoryStruct chunk1;
    curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk1);

    // Useragent
    curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0
(Windows; U; Windows NT 5.1; de; rv:1.8.1.7) Gecko/20070914
Firefox/2.0.0.7");

    // Individuelle Header Informationen
    struct curl_slist * slist=NULL;
    slist = curl_slist_append(slist, "Accept-Language:
de-de,de;q=0.8,en-us;q=0.5,en;q=0.3");
    curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);

    // Weiterleitungen folgen
    curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
    // SSL | Host verifizieren
    curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1);
    // SSL | Pfad der pem-Datei
    curl_easy_setopt(curl_handle, CURLOPT_CAINFO,
"C:\\Project\\libcurl\\VisualStudio\\MyApplication\\Release\\cacert.pem");
    // Cookie-Engine starten
    curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "");
    // Alte Cookies löschen
    curl_easy_setopt(curl_handle, CURLOPT_COOKIELIST, "ALL");
    // Abzufragende URL
    curl_easy_setopt(curl_handle, CURLOPT_URL,
"https://gif-plugin.dev.java.net/logo.gif");

    curl_easy_perform(curl_handle);
   
    if(chunk1.memory)
    {
        // Output of the data
       
        // Free
        free(chunk1.memory);
    }

    // Aufräumen
    curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, NULL);
    curl_slist_free_all(slist);

    return true;
}

Part2:
    size_t WriteMemoryCallback3(void *ptr, size_t size, size_t nmemb,
void *data)
    {
      size_t realsize = size * nmemb;
      struct CCommunicator_MemoryStruct *mem = (struct
CCommunicator_MemoryStruct *)data;

      mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize
+ 1);

      if (mem->memory)
      {
        memcpy(&(mem->memory[mem->size]), ptr, realsize);
        mem->size += realsize;
        mem->memory[mem->size] = 0;
      }

      return realsize;
    }

Thanks a lot for your help!
Michael
Received on 2008-02-15