1.如何移植curl库:略
2.调用API:
size_t ezDownloadWriteData(void *ptr, size_t size, size_t nmemb, void *stream)
{
return fwrite(ptr, size, nmemb, stream);
}int ezDownloadFunc(char *url, char *path)
{
CURL *curl;
FILE *ez_fp=NULL;curl_global_init(CURL_GLOBAL_ALL);
curl=curl_easy_init();
if(curl == NULL){
printf("curl_easy_init error\n");
goto end;
}if((ez_fp=fopen(path,"w"))==NULL){
printf("create file error\n");
goto end;
}curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, ez_fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ezDownloadWriteData);
if(curl_easy_perform(curl) != CURLE_OK){
printf("curl_easy_perform error\n");
goto end;
}else{
printf("download ok\n");
return 1;
}end:
curl_easy_cleanup(curl);
curl_global_cleanup();
if(ez_fp)
fclose(ez_fp);
return 0;
}
3.调用:
ezDownloadFunc("http://192.168.4.2/index.html","/tmp/index.html");