int CHttpClient::download(std::string url, std::string local_file, int down_speed)
{
CURL *image;
CURLcode imgresult;
FILE *fp = NULL;
//url_download.c_str();
image = curl_easy_init();
if (image)
{
//Open File
fp = fopen(local_file.c_str(), "wb");
if (fp == NULL)
{
//cout << "File cannot be opened";
return CURLE_RECV_ERROR;
}
if (0 == strncmp(url.c_str(), "https:", 6)) //关闭验证
{
curl_easy_setopt(image, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(image, CURLOPT_SSL_VERIFYHOST, FALSE);
}
curl_easy_setopt(image, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(image, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(image, CURLOPT_URL, url.c_str());
curl_easy_setopt(image, CURLOPT_FOLLOWLOCATION, 1);
//这里限速 100KB/s
//curl_easy_setopt(image, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t)1000 * 1024 * 8);
curl_easy_setopt(image, CURLOPT_NOPROGRESS, 0);
//CURLOPT_RESUME_FROM
// Grab image
imgresult = curl_easy_perform(image);
if (imgresult)
{
//cout << "Cannot grab the File!\n";
return CURLE_RECV_ERROR;
}
//Clean up the resources
curl_easy_cleanup(image);
//Close the file
fclose(fp);
}
return 0;
}
下载完后用unzip解压