curl-library
How does curl_easy_getinfo CURLINFO_CONTENT_LENGTH_DOWNLOAD work?
Date: Thu, 5 Jan 2012 19:59:47 +0100
Hello,
I have been hacking around with cUrl and I want to use it to download a page to the memory buffer.
And I tried to do the following:
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
CURLcode res;
CURL *curl;
void *buffer;
size_t iolen;
char *buf;
double sz;
int m_sz;
if((curl = curl_easy_init())) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/?q=curl");
if((res = curl_easy_perform(curl)) == 0) {
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &sz);
m_sz = (int)sz+1;
buf = (char*)malloc(m_sz);
if(buf == NULL) { printf("memerr\n"); return 0; }
printf("BuffSize: %d\n", m_sz);
if((res = curl_easy_recv(curl, buf, sz, &iolen)) == 0) {
printf("Success!\n");
return 0;
} else {
printf("Fail!\n");
curl_easy_cleanup(curl);
return -1;
}
}
}
return -1;
}
But it keeps saying Fail.
My question would be, which part of the documentation did I interpret wrong?
Thanks!
-- Kind Regards, Robin Vossen Please avoid sending me Word, Excel or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.htmlReceived on 2012-01-05