curl 笔记, 记录一下,有空再整理一下

本文深入解析了使用CURL进行HTTPS网页内容下载时,如何配置SSL验证并实现多线程并发处理。介绍了CURLOPT_CAINFO、CURLOPT_SSL_VERIFYPEER、CURLOPT_SSL_VERIFYHOST选项的用法,演示了如何安全高效地初始化和清理CURL会话,以及利用CURL获取上传/下载内容长度的方法。此外,还详细解释了CURLOPT_CAINFO参数的设置、使用curl_easy_duphandle复制会话以避免内存冲突,并通过curl_slist_append管理字符串列表。最后,文章阐述了CURL API分类及其相互关系,包括curl_easy、curl_multi、curl_shared系列函数和辅助函数如curl_slist、curl_mprintf等。
1. curL 下载Https 网页的内容 编译的libcurl 需支持ssl

    curl_easy_setopt(handle,CURLOPT_CAINFO,"ca.crt");
    curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER,  1L);
    curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST,  1L);

2. curl 的 easy_init 等函数是thread_safe,只需要保证在每个线程里面初始化curl的库函数即可。
    
    test_curl(){
        curl_easy_init();
        .....
        curl_easy_cleanup();
    }

    boost::thread n1(test_curl);
    boost::thread n2(test_curl);
    boost::thread n3(test_curl);
    boost::thread n4(test_curl);
    boost::thread n5(test_curl);
    ......
    n1.join();
    n2.join();
    .........

--> OK  


3. using of  curl lib
    curl = curl_easy_init
    curl_easy_cleanup(curl);
    curl_easy_reset() -->   reset curl handle to initialize status

4. curl_easy_getinfo
    can get the  content-length of Upload/Download
                current size of Upload/Download

5. curl_easy_duphandle
    it dump a new handler with the same options as the previous one, u also can use it independently, but two handler use the only one options memory.
    u 'd better not use the function if u not enough reason.

6.  curl_slist_append
    struct curl_slist * curl_slist_append(struct curl_slist * list, const char * string)
    save the string into the slist;
    same function as parameters of readv(), sendv()
    
see also:
    curl_slist_free_all(struct curl_slist * list);

7. curl API 分类及关系
    1) curl_easy 系列
    2) curl_multi系列
    3) curl_shared系列
    4) Portable helpFunction
    1) curl_easy 系列 如上
    2) curl_multi
        使用select类似的函数,支持同时处理多个网络通信状态,每一个handle是一个curl_easyhandle
    3) curl_shared ????
        to use the shared data in multi-thread environment

    4)Help Function
        4.1) curl_slist        string list
        4.2) curl_mprintf    printf
        4.3) curl_form   Gen the FormData
        4.4) curl_escape URL Encoding&Decoding
        4.5) curl_getdate
        4.6) curl_getenv


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值