CURL 实现文件下载
#include <iostream>
#include <fstream>
#include <curl/curl.h>
void GetRemoteFileByCurl(const char* url, const char* savepath)
{
CURL *curl;
FILE *fp;
CURLcode res;
curl = curl_easy_init();
if (curl) {
fp = fopen(savepath,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
}
int main()
{
std::cout<<"hello world"<<std::endl;
std::string url = "http://192.168.1.236:9000/seenton-alarm/images/offline/2023-04-07/1680855463536.jpg";
std::string savepath = "./123.jpg";
GetRemoteFileByCurl(url.c_str(),savepath.c_str());
return 1;
}