文章3:libcurl基本编程概述
转载请注明出处http://blog.csdn.net/yankai0219/article/details/8159697
0.序
1.简单用例
2.论述说明
3.更为复杂的例子
4.总结
0.序 前一段时间,因为项目需要,恶补了一番libcurl的内容,故记录下来。至于安装啥的就请大家参阅官方文档。http://curl.haxx.se/docs/install.html 任何时候学习任何东西,官方的文档绝对是最好的教程。http://curl.haxx.se/libcurl/c/ 1.简单案例 下面首先给出一个官方的基本示例,该示例中使用了几个easy interface。我将其称为基本用例
#include <stdio.h>#include <curl/curl.h> int main(void){ CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); } return 0;}