一:
1,全局初始化及释放:
CURLcode curl_global_init(long flags)

flags: CURL_GLOBAL_ALL //初始化所有的可能的调用。

CURL_GLOBAL_SSL //初始化支持 安全套接字层。

CURL_GLOBAL_WIN32 //初始化win32套接字库。

CURL_GLOBAL_NOTHING //没有额外的初始化。

这个函数只能用一次。(其实在调用curl_global_cleanup 函数后仍然可再用)

如果这个函数在curl_easy_init函数调用时还没调用,它讲由libcurl库自动调用,所以多线程下最好主动调用该函数以防止在线程中curl_easy_init时多次调用。

注意:虽然libcurl是线程安全的,但curl_global_init是不能保证线程安全的,所以不要在每个线程中都调用curl_global_init,应该将该函数的调用放在主线程中。

void curl_global_cleanup(void)

二:两种模式
1,
The easy interface is a synchronous, efficient, quickly used and... yes, easy interface for file transfers. Numerous applications have been built using this.
The multi interface is the asynchronous brother in the family and it also offers multiple transfers using a single thread and more. Get a grip of how to work with it in the multi interface overview.

easy interface 同步的快速的,多用于文件传输。
multi interface 异步的,支持一个或多个线程里面的多个文件传输。

https://curl.haxx.se/libcurl/c/libcurl-easy.html
https://curl.haxx.se/libcurl/c/libcurl-multi.html

三:easy interface
1,初始化下载handle及释放

CURL *easy_handle =     curl_easy_init();

curl_easy_cleanup(easy_handle);

2,CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);

CURLoption枚举了curl能做的所有操作。
设置回调函数,访问URL,超时时间,断点续传等。

3,CURLcode curl_easy_perform(CURL * easy_handle );
前面初始化init,属性steopt设置好后就调perform开始执行起来。

4,easy interface常用的函数
curl_easy_init()

curl_easy_cleanup()

curl_easy_setopt()

curl_easy_perform()

curl_easy_getinfo()

While the above functions are the main functions to use in the easy interface, there is a series of other helpful functions too including:

curl_version()

returns a pointer to the libcurl version string

curl_getdate()

converts a date string to time_t

curl_formadd()

build multipart form-data posts

curl_formfree()

free a previously built form POST

curl_slist_append()

builds a linked list

curl_slist_free_all()

frees a whole curl_slist as made with curl_slist_append()

curl_easy_escape()

URL encodes a string

curl_easy_unescape()

URL decodes a string

5,
问题:
1>MCurl.obj : error LNK2019: unresolved external symbol __imp__curl_easy_cleanup referenced in function _main

1>MCurl.obj : error LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function _main

解决:
1,C/C++->Preprocessor->Definitions 增加:
BUILDING_LIBCURL HTTP_ONLY或 CURL_STATICLIB CURL_DISABLE_LDAP

2,附加ws2_32.lib和wldap32.lib

6,
上面配置release下没问题,dubug下会报启动错误!

7,debug下的一些问题
问题:

解决:
上面提示already defined in LIBCMTD,去熟悉里面设置忽略LIBCMTD
下面根据列出缺少的函数名在MSDN搜对应的lib添加上

问题:
编译通过了但是启动失败

解决:
去查下提示的manifest文件

左边的debug的,右边是release的,按照右边吧762移到6195上面去。(因为relase启动没问题所以我以726版本为准)

Generate Manifest设为NO防止重编译又把手动修改后的manifest改回去。

启动提示缺MSVCR80D.dll,下载一个加上。

然后启动,运行库崩溃,算了先用release,libcurld.lib可能有问题后面再编一个。

 

8,
https://curl.haxx.se/libcurl/c/example.html
官网提供的列子自己编译运行看下。

Libcurl笔记一的更多相关文章

  1. LibCurl笔记四

    1,curl设置fiddler代理curl_easy_setopt(m_easyHandle, CURLOPT_PROXY, "127.0.0.1:8888"); 2,

  2. Libcurl笔记二

    一: multi与easy接口的不同处The multi interface offers several abilities that the easy interface doesn't. The ...

  3. Libcurl笔记五_easy模式运行原理

    1, curl_easy_init内部调用Curl_open创建一个结构体SessionHandle(里面包含了所以curl使用的数据和指针)并初始化一些数据,然后返回将其作为给外侧使用的句柄CURL ...

  4. Libcurl笔记三

    一,post请求和回报处理 //"host/path?extra" //strHttp=" http://portal.liuhan.com:/web/getConfig ...

  5. 笔记整理--LibCurl开发

    LibCurl开发_未了的雨_百度空间 - Google Chrome (2013/7/26 21:11:15) LibCurl开发 一:LibCurl 编程流程1.调用curl_global_ini ...

  6. Yocto开发笔记之《嵌入式linux libcurl编程》(QQ交流群:519230208)

    开了一个交流群,欢迎爱好者和开发者一起交流,转载请注明出处. QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 =============================== ...

  7. Nginx快速入门菜鸟笔记

    Nginx快速入门-菜鸟笔记   1.编译安装nginx 编译安装nginx 必须先安装pcre库. (1)uname -a 确定环境 Linux localhost.localdomain 2.6. ...

  8. Linux下编译LibCURL

    编译环境 操作系统: Red Hat Enterprise Linux Server release 5.4 64-bit 编译工具: gcc (GCC) 4.1.2 20080704 (Red Ha ...

  9. qt5集成libcurl实现tftp和ftp的方法一:搭建环境(五篇文章)

    最近使用QT5做一个软件,要求实现tftp和ftp文件传输,使用QT5开发好UI界面等功能,突然发现QT5不直接提供tftp和ftp支持,无奈之下只好找第三方库来间接实现,根据网友的介绍,libcur ...

随机推荐

  1. C# Func<>托付

    曾经我们为了可以调用一个方法.必须比照这种方法定义一个对应的delegate. 原先我们定义delegate // 托付声明 -- 定义一个签名: delegate double MathAction ...

  2. hibernate 实体关系映射笔记

    @经常使用属性说明:     @Entity:实体类     @Table:指定相应数据表     @Id:主键,使用能够为null值的类型,假设实体类没有保存到数据库是一个暂时状态     @Col ...

  3. android147 360 程序锁

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  4. Linux内核初始化定义

    转载:http://blog.csdn.net/beatbean/article/details/8448623 1. Compile宏控制 位于include/linux/init.h /* The ...

  5. java笔记00-目录

    --2013年7月26日17:49:59 学习java已久,趁最近有空,写一个总结: java笔记01-反射:

  6. 关于JDK中的总结和基本知识总结

    人机交互的图形化界面(GUI) 命令行方式(CLI  command line interface) JDK有不同的版本(linux,mac os, windows) Java 的跨平台性. 软件放到 ...

  7. 练习题之ExChange

    两个线程可以交换对象的同步点.每个线程都在进入exChange方法时给出某个对象,并接受其他线程返回时给出的对象.用于实现两个人之间的数据交换,每个人在完成一定的事务后想与对方交换数据,第一个先拿出数 ...

  8. hdu 1892 树状数组

    思路:就是一个很普通的二维树状数组,注意的是x1,y1不一定在x2,y2的左下方. #include<iostream> #include<cstring> #include& ...

  9. eclipse导入安卓工程时出现 Invalid project description. overlaps the location of another project提示

    eclipse导入工程时出现了如下问题: Invalid project description. /Users/yang/Documents/workspace/BarCodeTest overla ...

  10. linux信息查找

    问题: 1. 当使用一台linux机器的时候,常常需要确认当前所用操作系统的版本信息,内核信息等, 操作系统的版本信息可以通过以下命令完成,比如:lsb_release -a:cat /etc/iss ...