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 ...
随机推荐
- 在VS2012下不安装VS2010编译VS2010的工程
虽然一路追随这VISUAL SUTDIO在编程,但是断档的情况还是有的,最近一次硬盘问题使得安装了所有的VS2003-VS2012的机器硬盘挂了,无奈只能够安装了,不过觉得没啥用了,就安装一个VS20 ...
- mybatis 关联映射传递多参数方法
<resultMap type="com.secoo.my.bean.OrderItemComment" id="orderItemResult"> ...
- 日志分析(五) PV&UV
应用设计请求之初,对于url有一定的规划.因此,请求的url格式类似如下: /**/school/****?token=a66cb2a3-e0b7-4f0a-b332-********* token唯 ...
- asp.net获取客户端IP,Mac
public class GetClientInfo { [DllImport("Iphlpapi.dll")] private static extern int SendARP ...
- VBA Excel 打印
1. 设置 页边距.打印区域 With .PageSetup .HeaderMargin = Application.CentimetersToPoints(0.5) .LeftMargin = Ap ...
- Helpers\RainCaptcha
Helpers\RainCaptcha This class can validate CAPTCHA images with RainCaptcha. It can generate an URL ...
- Linux shell 脚本攻略之创建不可修改文件
摘自:<Linux shell 脚本攻略>
- c实例_挑战程序竞赛,蚂蚁
#include <stdio.h> //蚂蚁的题目 int max(int a,int b) { int count; count=a>b?a:b; return count; } ...
- Virtualbox - 共享文件夹
在虚拟机中添加共享文件夹——比如主机中的/home/user/download,我想把download文件夹共享给虚拟机用. 步骤:1.在虚拟机中找个挂载的目录,比如 /mnt/d,没有就新建一个目录 ...
- 利用OPENSSL 实现MD5加密。
#include <stdio.h> #include "openssl/evp.h" #include "openssl/md5.h" #incl ...