Libcurl笔记一

Libcurl笔记一,第1张

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:

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
官网提供的列子自己编译运行看下。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/587039.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存