Libcurl笔记一
一:
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:
returns a pointer to the libcurl version string |
|
converts a date string to time_t |
|
build multipart form-data posts |
|
free a previously built form POST |
|
builds a linked list |
|
frees a whole curl_slist as made with curl_slist_append() |
|
URL encodes a string |
|
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笔记一的更多相关文章
- LibCurl笔记四
1,curl设置fiddler代理curl_easy_setopt(m_easyHandle, CURLOPT_PROXY, "127.0.0.1:8888"); 2,
- Libcurl笔记二
一: multi与easy接口的不同处The multi interface offers several abilities that the easy interface doesn't. The ...
- Libcurl笔记五_easy模式运行原理
1, curl_easy_init内部调用Curl_open创建一个结构体SessionHandle(里面包含了所以curl使用的数据和指针)并初始化一些数据,然后返回将其作为给外侧使用的句柄CURL ...
- Libcurl笔记三
一,post请求和回报处理 //"host/path?extra" //strHttp=" http://portal.liuhan.com:/web/getConfig ...
- 笔记整理--LibCurl开发
LibCurl开发_未了的雨_百度空间 - Google Chrome (2013/7/26 21:11:15) LibCurl开发 一:LibCurl 编程流程1.调用curl_global_ini ...
- Yocto开发笔记之《嵌入式linux libcurl编程》(QQ交流群:519230208)
开了一个交流群,欢迎爱好者和开发者一起交流,转载请注明出处. QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 =============================== ...
- Nginx快速入门菜鸟笔记
Nginx快速入门-菜鸟笔记 1.编译安装nginx 编译安装nginx 必须先安装pcre库. (1)uname -a 确定环境 Linux localhost.localdomain 2.6. ...
- Linux下编译LibCURL
编译环境 操作系统: Red Hat Enterprise Linux Server release 5.4 64-bit 编译工具: gcc (GCC) 4.1.2 20080704 (Red Ha ...
- qt5集成libcurl实现tftp和ftp的方法一:搭建环境(五篇文章)
最近使用QT5做一个软件,要求实现tftp和ftp文件传输,使用QT5开发好UI界面等功能,突然发现QT5不直接提供tftp和ftp支持,无奈之下只好找第三方库来间接实现,根据网友的介绍,libcur ...
随机推荐
- URAL 1775 B - Space Bowling 计算几何
B - Space BowlingTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- LeetCode: Reverse Words in a String:Evaluate Reverse Polish Notation
LeetCode: Reverse Words in a String:Evaluate Reverse Polish Notation Evaluate the value of an arithm ...
- 20种常用的DOS命令小结
先介绍一下通配符的概念. 通配符*和? *表示一个字符串 ?只代表一个字符 注意通配符只能通配文件名或扩展名,不能全都表示.例如我们要查找以字母y开头的所有文件,可以输入以下命令:dir y*.*:如 ...
- Getting Started with Zend Framework MVC Applications
Getting Started with Zend Framework MVC Applications This tutorial is intended to give an introducti ...
- Face The Right Way
Face The Right Way Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2564 Accepted: 117 ...
- Turn the pokers
Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...
- PHP读书笔记(7)- 函数
自定义函数 PHP内置了超过1000个函数,因此函数使得PHP成为一门非常强大的语言.大多数时候我们使用系统的内置函数就可以满足需求,但是自定义函数通过将一组代码封装起来,使代码进行复用,程序结构与逻 ...
- PHP正则提取或替换img标记属性实现文章预览
今天在想如何实现文章预览时,如果文章里面包含照片,那么就选取第一张照片作为预览图,如果没有照片,则截取文章的头150个字作为预览文字,但是因为保存在数据库的文章都是以富文本的形式,没办法直接提取,在网 ...
- 阿里云ubuntu搭建SVN服务器
系统:Ubuntu 14.04 64位 新手注意:连接到服务器之后,默认会在用户文件夹位置“~”,使用cd /命令可以回到根目录.SVN搭在公共的位置比较稳妥. 1.通过apt-get安装subver ...
- CSS的总结(选择器,伪类等...)
关于组合选择器可参考:http://www.cnblogs.com/starof/p/4453458.html 主要内容 CSS概述 CSS和HTML结合的四种方式 CSS样式优先级和代码规范 CSS ...