Libcurl筆記一-創(chuàng)新互聯(lián)

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

創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:做網(wǎng)站、成都網(wǎng)站建設、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的利州網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!

flags: CURL_GLOBAL_ALL //初始化所有的可能的調(diào)用。

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

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

CURL_GLOBAL_NOTHING //沒有額外的初始化。

這個函數(shù)只能用一次。(其實在調(diào)用curl_global_cleanup 函數(shù)后仍然可再用)

如果這個函數(shù)在curl_easy_init函數(shù)調(diào)用時還沒調(diào)用,它講由libcurl庫自動調(diào)用,所以多線程下最好主動調(diào)用該函數(shù)以防止在線程中curl_easy_init時多次調(diào)用。

注意:雖然libcurl是線程安全的,但curl_global_init是不能保證線程安全的,所以不要在每個線程中都調(diào)用curl_global_init,應該將該函數(shù)的調(diào)用放在主線程中。

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能做的所有操作。
設置回調(diào)函數(shù),訪問URL,超時時間,斷點續(xù)傳等。

3,CURLcode curl_easy_perform(CURL * easy_handle );
前面初始化init,屬性steopt設置好后就調(diào)perform開始執(zhí)行起來。

4,easy interface常用的函數(shù)
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
下面根據(jù)列出缺少的函數(shù)名在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
官網(wǎng)提供的列子自己編譯運行看下。

新聞標題:Libcurl筆記一-創(chuàng)新互聯(lián)
新聞來源:http://muchs.cn/article14/csjege.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護動態(tài)網(wǎng)站、企業(yè)建站網(wǎng)站策劃、網(wǎng)站內(nèi)鏈、服務器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設