curl-library
Cant Get the File size from HTTP Server
Date: Sun, 12 Apr 2009 08:41:23 +0000
Hello ...
I don't know if i miss something but I cant get the file size from the
server ..
here is my code
#include <windows.h>
#include <winbase.h>
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <time.h>
/* ---------------------------- */
/* writing function */
size_t WriteFunc( void *ptr, size_t size, size_t nmemb, void *stream)
{
int written = fwrite(ptr,size,nmemb,(FILE*)stream);
return written;
}
/* ---------------------------- */
/* Progress function */
int progress_callback(void *clientp,double dltotal,double dlnow,
double ultotal,double ulnow)
{
printf("total of file : %12.2f | Downloaded :
%12.2f\n",dltotal,dlnow) ;
return 0 ;
}
/* thread function */
void DownThread(void *p)
{
const char *fname =/*"codeblocks-8.02-setup.exe";*/ "zlib123.zip";
CURL *cu ;
FILE *fp ;
CURLcode c;
cu = curl_easy_init() ;
c = curl_easy_setopt(cu,CURLOPT_URL,"
http://www.gzip.org/zlib/zlib-1.2.3.tar.gz"/*"
http://www.zlib.net/zlib123.zip"*/);
c = curl_easy_setopt(cu,CURLOPT_PROXY,"192.168.0.1:8080");
c = curl_easy_setopt(cu,CURLOPT_PROXYUSERPWD,"saidus:thalla123");
c = curl_easy_setopt(cu,CURLOPT_NOBODY,1);
//c = curl_easy_setopt(cu,CURLOPT_WRITEFUNCTION,WriteFunc);
//c = curl_easy_setopt(cu,CURLOPT_NOPROGRESS,0);
//c = curl_easy_setopt(cu,CURLOPT_PROGRESSDATA,pp);
//c = curl_easy_setopt(cu,CURLOPT_PROGRESSFUNCTION,progress_callback);
fp = fopen(fname, "wb") ;
if (fp==NULL) { curl_easy_cleanup(cu) ; exit(-1) ; }
c = curl_easy_setopt(cu,CURLOPT_WRITEDATA,fp);
c = curl_easy_perform(cu);
double *cl, f;
char *cc ;
c = curl_easy_getinfo(cu,
CURLINFO_CONTENT_LENGTH_DOWNLOAD/*CURLINFO_CONTENT_TYPE*/
/*CURLINFO_HEADER_SIZE*/, &cl);
//f = *cl;
printf("the File size is : %f", cl );
fclose(fp);
curl_easy_cleanup(cu) ;
}
int main(int argc, char *argv[])
{
// HANDLE h;
// h = (HANDLE)_beginthread(DownThread,0,NULL);
// WaitForSingleObject(h,INFINITE);
DownThread(NULL);
return 0;
}
Received on 2009-04-12