日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Libcurl安装与HelloWorld

發布時間:2024/7/23 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Libcurl安装与HelloWorld 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Windows系統下源代碼下載編譯、安裝方式如下:
https://blog.csdn.net/fxbjye/article/details/89152849
編譯后得到庫文件,把這兩個文件復制到項目文件中,

修改項目文件的屬性,

修改附加依賴項:

輸入代碼:

#include <stdio.h> #include <string.h> #include <curl.h> #define MAX_BUF 65536 char wr_buf[MAX_BUF + 1]; int wr_index;/* * Write data callback function (called within the context of * curl_easy_perform. */ size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) {int segsize = size * nmemb;/* Check to see if this data exceeds the size of our buffer. If so,* set the user-defined context value and return 0 to indicate a* problem to curl.*/if (wr_index + segsize > MAX_BUF) {*(int *)userp = 1;return 0;}/* Copy the data from the curl buffer into our buffer */memcpy((void *)&wr_buf[wr_index], buffer, (size_t)segsize);/* Update the write index */wr_index += segsize;/* Null terminate the buffer */wr_buf[wr_index] = 0;/* Return the number of bytes received, indicating to curl that all is okay */return segsize; }/* * Simple curl application to read the index.html file from a Web site. */ int main(void) {CURL *curl;CURLcode ret;int wr_error;wr_error = 0;wr_index = 0;/* First step, init curl */curl = curl_easy_init();if (!curl) {printf("couldn't init curl\n");return 0;}/* Tell curl the URL of the file we're going to retrieve */curl_easy_setopt(curl, CURLOPT_URL, "www.baidu.com");/* Tell curl that we'll receive data to the function write_data, and* also provide it with a context pointer for our error return.*/curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&wr_error);curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);/* Allow curl to perform the action */ret = curl_easy_perform(curl);printf("ret = %d (write_error = %d)\n", ret, wr_error);/* Emit the page if curl indicates that no errors occurred */if (ret == 0) printf("%s\n", wr_buf);curl_easy_cleanup(curl);return 0; }

輸出結果為:

總結

以上是生活随笔為你收集整理的Libcurl安装与HelloWorld的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。