一:
1,全局初始化及釋放:
CURLcode curl_global_init(long flags)
flags: CURL_GLOBAL_ALL //初始化所有的可能的調(diào)用。
CURL_GLOBAL_SSL //初始化支持 安全套接字層。
CURL_GLOBAL_WIN32 //初始化win32套接字庫。
CURL_GLOBAL_NOTHING //沒有額外的初始化。
這個(gè)函數(shù)只能用一次。(其實(shí)在調(diào)用curl_global_cleanup 函數(shù)后仍然可再用)
如果這個(gè)函數(shù)在curl_easy_init函數(shù)調(diào)用時(shí)還沒調(diào)用,它講由libcurl庫自動(dòng)調(diào)用,所以多線程下最好主動(dòng)調(diào)用該函數(shù)以防止在線程中curl_easy_init時(shí)多次調(diào)用。
注意:雖然libcurl是線程安全的,但curl_global_init是不能保證線程安全的,所以不要在每個(gè)線程中都調(diào)用curl_global_init,應(yīng)該將該函數(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 異步的,支持一個(gè)或多個(gè)線程里面的多個(gè)文件傳輸。
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能做的所有操作。
設(shè)置回調(diào)函數(shù),訪問URL,超時(shí)時(shí)間,斷點(diǎn)續(xù)傳等。
3,CURLcode curl_easy_perform(CURL * easy_handle );
前面初始化init,屬性steopt設(shè)置好后就調(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下會(huì)報(bào)啟動(dòng)錯(cuò)誤!
7,debug下的一些問題
問題:
解決:
上面提示already defined in LIBCMTD,去熟悉里面設(shè)置忽略LIBCMTD
下面根據(jù)列出缺少的函數(shù)名在MSDN搜對(duì)應(yīng)的lib添加上
問題:
編譯通過了但是啟動(dòng)失敗
解決:
去查下提示的manifest文件
左邊的debug的,右邊是release的,按照右邊吧762移到6195上面去。(因?yàn)閞elase啟動(dòng)沒問題所以我以726版本為準(zhǔn))
Generate Manifest設(shè)為NO防止重編譯又把手動(dòng)修改后的manifest改回去。
啟動(dòng)提示缺MSVCR80D.dll,下載一個(gè)加上。
然后啟動(dòng),運(yùn)行庫崩潰,算了先用release,libcurld.lib可能有問題后面再編一個(gè)。
8,
https://curl.haxx.se/libcurl/c/example.html
官網(wǎng)提供的列子自己編譯運(yùn)行看下。
新聞標(biāo)題:Libcurl筆記一-創(chuàng)新互聯(lián)
新聞來源:http://www.rwnh.cn/article14/csjege.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、動(dòng)態(tài)網(wǎng)站、企業(yè)建站、網(wǎng)站策劃、網(wǎng)站內(nèi)鏈、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容