curl-library
Encoding issue getting an image with libcURL
Date: Tue, 8 Feb 2005 12:26:19 -1000
I am trying to get an image and write it to a file. It apparently works since I
do receive an image, however the content of the image is completely wrong. When
I compare the image I get with my code and the original, I notice some
discrepencies. It seems to be relate to the wen carriage returns are encoded. I
compile the following code on windows platfrom with VC++ 7.1.
Regards,
Julien
---------------------------------------------------
#include <stdio.h>
#include <curl/curl.h>
size_t writeFunction( void *ptr, size_t size, size_t nmemb, void *stream)
{
fwrite(ptr, size, nmemb, (FILE *)stream);
return nmemb*size;
};
int main(void)
{
CURL *curl;
CURLcode res;
FILE *destFile;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL,
"http://www.google.com/images/logo.gif");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
// Open the file to write the copied file to
destFile = fopen("myImage.gif,"w");
// Tell libcurl where to write the file
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,writeFunction);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,destFile);
res = curl_easy_perform(curl);
/* always cleanup */
fclose(destFile);
curl_easy_cleanup(curl);
}
return 0;
}
Received on 2005-02-08