利用curl计算网络文件大小

时间:2022-12-01 12:52:57
     double zipsize = ;
CURL *handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_URL, url);
curl_easy_setopt(handle, CURLOPT_HEADER, ); //只需要header头
curl_easy_setopt(handle, CURLOPT_NOBODY, ); //不需要body if (curl_easy_perform(handle) == CURLE_OK)
{
curl_easy_getinfo(handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &zipsize);
packageBytesTotal = (int)((zipsize / ) + 0.5);
std::cout << "当前要加载的包大小为: " << packageBytesTotal << "KB" << std::endl;
}
curl_easy_cleanup(handle);