cURL 노트 의 3 디 스 플레이 진도

Technorati 태그:curl
이 문장http://www.cppblog.com/izualzhy/archive/2012/07/14/183386.html변동 이 크 지 않 고 진 도 를 표시 하 는 인터페이스 만 사용 했다.
/*
 * =====================================================================================
 *       Filename:  save_url.c
 *    Description:    url     
 *
 *        Version:  1.0
 *        Created:  07/14/2012 12:28:43 PM
 *
 *         Author:  zhy (), [email protected]
 * =====================================================================================
 */

#include <stdio.h>

#include <curl/curl.h>

//            :
//size_t function(char* ptr, size_t size, size_t nmemb, void *userdata);
//usedata    CURLOPT_WRITEDATA  
//         ,       (FILE*)
size_t writeData(char* ptr, size_t size, size_t nmemb, void* stream)
{
    int written = fwrite(ptr, size, nmemb, (FILE *)(stream));
    return written;
}

/*            :
 * int function(void* clientp, double dltotal, double dlnow, double ultotal, double ulnow)
 * clientp    CURLOPT_PROGRESSDATA  
 *             ,      */
int progress(void* clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{
    printf("------ %.2f%% ------
"
, dlnow/dltotal); return 0; } int main() { CURL* curl; CURLcode res; /* , CURL* */ curl = curl_easy_init(); /* URL */ curl_easy_setopt(curl, CURLOPT_URL, "http://www.baidu.com"); /* */ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData); FILE* fp = fopen("baidu_curl.html", "w"); if (fp == NULL) { curl_easy_cleanup(curl); return -1; } /* userdata*/ /* , FILE* */ curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); /* 0 */ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); /* */ curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress); res = curl_easy_perform(curl); if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s
"
, /* CURLcode */ curl_easy_strerror(res)); /* */ fclose(fp); /* , , curl_easy_init */ curl_easy_cleanup(curl); return 0; }

좋은 웹페이지 즐겨찾기