利用curl计算网络文件大小

 1     double zipsize = 0;
 2     CURL *handle = curl_easy_init();
 3     curl_easy_setopt(handle, CURLOPT_URL, url);
 4     curl_easy_setopt(handle, CURLOPT_HEADER, 1);   //只需要header头
 5     curl_easy_setopt(handle, CURLOPT_NOBODY, 1);   //不需要body
 6 
 7     if (curl_easy_perform(handle) == CURLE_OK)
 8     {
 9      curl_easy_getinfo(handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &zipsize);
10         packageBytesTotal = (int)((zipsize / 1000) + 0.5);
11         std::cout << "当前要加载的包大小为: " << packageBytesTotal << "KB" << std::endl;
12     }
13     curl_easy_cleanup(handle);

 

posted @ 2014-08-15 15:14  居家懒人  阅读(2790)  评论(0编辑  收藏  举报