亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 4047 | 回復(fù): 4
打印 上一主題 下一主題

libcurl的第一個(gè)例子是不是有問(wèn)題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2012-06-26 11:09 |只看該作者 |倒序?yàn)g覽
就是那個(gè)simple.c,代碼如下:
  1. #include <stdio.h>
  2. #include <curl/curl.h>

  3. int main(void)
  4. {
  5.   CURL *curl;
  6.   CURLcode res;

  7.   curl = curl_easy_init();
  8.   if(curl) {
  9.     curl_easy_setopt(curl, CURLOPT_URL, "http://www.163.com");
  10.     res = curl_easy_perform(curl);

  11.     /* always cleanup */
  12.     curl_easy_cleanup(curl);
  13.   }
  14.   return 0;
  15. }
復(fù)制代碼
simple.c shows how to get a remote web page in only four libcurl function calls.
simple.c 這個(gè)例子告訴你,僅僅需要4個(gè)libcurl函數(shù),就能獲取一個(gè)網(wǎng)頁(yè)。

執(zhí)行沒(méi)有任何結(jié)果,必須寫(xiě)成回調(diào)的方式,才能打印輸出,按照文檔里說(shuō)的,這個(gè)例子似乎會(huì)輸出到stdout的。
文檔libcurl-tutorial - libcurl programming tutorial 里有如下一段:
libcurl offers its own default internal callback that will take care of the data if you don't set the callback with CURLOPT_WRITEFUNCTION. It will then simply output the received data to stdout. You can have the default callback write the data to a different file handle by passing a 'FILE *' to a file opened for writing with the CURLOPT_WRITEDATA option.

以下是回調(diào)的寫(xiě)法:
  1. #include <stdio.h>
  2. #include <curl/curl.h>

  3. size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
  4. {
  5.     printf("%s",(char*)buffer);
  6.    
  7.     return size*nmemb;
  8. }

  9. int main(void)
  10. {
  11.   CURL *curl;
  12.   CURLcode res;
  13.   char buf[2048] = {0};
  14.   
  15.   curl_global_init(CURL_GLOBAL_DEFAULT);
  16.   curl = curl_easy_init();
  17.   
  18.   if(curl) {
  19.     curl_easy_setopt(curl, CURLOPT_URL, "http://www.163.com");
  20.       
  21.     curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
  22.   
  23.     // curl_easy_setopt
  24.     res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
  25.     if(res != CURLE_OK){
  26.         printf("curl_easy_setopt not return CURLE_OK\n");
  27.     }
  28.     else{
  29.         printf("curl_easy_setopt exec success\n");
  30.     }
  31.    
  32.     // curl_easy_setopt
  33.    
  34. //   curl_easy_setopt(curl, CURLOPT_WRITEDATA, buf);

  35.     // curl_easy_perform
  36.     res = curl_easy_perform(curl);
  37.     if(res != CURLE_OK){
  38.         printf("curl_easy_perform not return CURLE_OK\n");
  39.     }
  40.     else{
  41.         printf("curl_easy_perform exec success\n");
  42.     }

  43. //   printf("buf:%s\n", buf);
  44.    
  45.     /* always cleanup */
  46.     curl_easy_cleanup(curl);
  47.   }
  48.   return 0;
  49. }
復(fù)制代碼

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2012-06-26 11:37 |只看該作者
沒(méi)研究過(guò)這個(gè)庫(kù),不知道問(wèn)題所在。

論壇徽章:
27
處女座
日期:2016-04-18 14:00:4515-16賽季CBA聯(lián)賽之福建
日期:2023-03-31 15:54:2315-16賽季CBA聯(lián)賽之深圳
日期:2020-06-02 10:10:5015-16賽季CBA聯(lián)賽之廣夏
日期:2019-07-23 16:59:452016科比退役紀(jì)念章
日期:2019-06-26 16:59:1315-16賽季CBA聯(lián)賽之天津
日期:2019-05-28 14:25:1915-16賽季CBA聯(lián)賽之青島
日期:2019-05-16 10:14:082016科比退役紀(jì)念章
日期:2019-01-11 14:44:062016科比退役紀(jì)念章
日期:2018-07-18 16:17:4015-16賽季CBA聯(lián)賽之上海
日期:2017-08-22 18:18:5515-16賽季CBA聯(lián)賽之江蘇
日期:2017-08-04 17:00:4715-16賽季CBA聯(lián)賽之佛山
日期:2017-02-20 18:21:13
3 [報(bào)告]
發(fā)表于 2012-06-26 12:31 |只看該作者
是這樣的,curl 庫(kù)都是使用回調(diào)函數(shù)來(lái)處理數(shù)據(jù)的,你要自己定義回調(diào)函數(shù)

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2012-06-26 12:55 |只看該作者
回復(fù) 3# evaspring


    明白,我已經(jīng)弄好了,

感覺(jué)文檔不準(zhǔn)確,浪費(fèi)了我的時(shí)間。

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2012-06-26 14:56 |只看該作者
我錯(cuò)了,看來(lái)是因?yàn)槲覍?duì)http協(xié)議不了解,因?yàn)?63那個(gè)主頁(yè)設(shè)置了跳轉(zhuǎn)。
所以后來(lái)加了句curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);才行
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP