C++ 基于libcurl的html 文件下载
lincurl的环境配置,在这里不做详细描述,代码实现程序如下:
#include <stdio.h>
#include <curl/curl.h>
/************************************************************************/
/* created by: mengxiapoxin date: 2014/12/9 */
/************************************************************************/
int main(void)
{
CURL *curl;
CURLcode res;
/* 调用curl_global_init()初始化libcurl */
res = curl_global_init(CURL_GLOBAL_ALL);
if (CURLE_OK != res)
{
printf("init libcurl failed.");
curl_global_cleanup();
return -1;
}
/* 调用curl_easy_init()函数得到 easy interface型指针 */
curl = curl_easy_init();
if(curl) {
/* 调用curl_easy_setopt()设置传输选项 */
curl_easy_setopt(curl, CURLOPT_URL, "http://blog.csdn.net/mxxlevel");
/* 调用curl_easy_perform()函数完成传输任务 */
res = curl_easy_perform(curl);
if(CURLE_OK == res) {
char *ct;
/* ask for the content-type */
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
if((CURLE_OK == res) && ct)
printf("We received Content-Type: %s\n", ct);
}
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
涉及到较多的参数类型回调,详细介绍点击这里http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
程序之路虽苦,可是苦中有甜,古往今来,多少人输在了心态,我要时刻保持积极的心态,欧耶

浙公网安备 33010602011771号