Hello everybody:
I am using libcurl 7.18.2 and VC++ 2008 and I use the
static library curllib.lib.
I would like to use libcurl to download a file from the http
server by segmenting it which using the curl_easy_setopt function and the
CURLOPT_RANGE flag.
My code is showed as below.
FILE* fp = NULL;
size_t write_data(void *ptr, size_t sz, size_t nmemb, void *stream)
{
if (!fp) {
fp = fopen("d:/test1.txt", "wb");
if (!fp) {
fprintf(stderr, "Fail to open file!\n");
return -1;
}
}
int written = fwrite(ptr, sz, nmemb, (FILE *)fp);
return written;
}
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL,
"http://www.google.com");
curl_easy_setopt(curl, CURLOPT_VERBOSE,
TRUE);
curl_easy_setopt(curl, CURLOPT_RANGE,
"0-100");
curl_easy_setopt(curl,
CURLOPT_RESUME_FROM, 0);
curl_easy_setopt(curl,
CURLOPT_WRITEFUNCTION, &write_data );
curl_easy_setopt(curl, CURLOPT_WRITEDATA,
fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
My problem is that I get more data than the size(this is 100),It seems all
webpage data is got.
But the console is show the text as below:
* About to connect() to www.google.com port 80 (#0)
* Trying 64.233.189.104... * connected
* Connected to www.google.com (64.233.189.104) port 80 (#0)
> GET / HTTP/1.1
Range: bytes=0-100
Host: www.google.com
Accept: */*
< HTTP/1.1 200 OK
< Cache-Control: private, max-age=0
< Date: Wed, 27 Aug 2008 10:02:45 GMT
< Expires: -1
< Content-Type: text/html; charset=ISO-8859-1
< Set-Cookie: PREF=ID=34b29390d0966fe6:NW=1:TM=1219831365:LM=1219831365:S=F2jHdL
ZGdfRMAjRH; expires=Fri, 27-Aug-2010 10:02:45 GMT; path=/; domain=.google.com
< Server: gws
< Transfer-Encoding: chunked
<
* Connection #0 to host www.google.com left intact
* Closing connection #0
I must be missing something. Please tell me.
Any help would be much appreciated.
Regards
dabang
-------------------------------------------------------------------
注册新浪2G免费邮箱(http://mail.sina.com.cn/)_______________________________________________
cURLpp mailing list
[email protected]
http://www.rrette.com/mailman/listinfo/curlpp