可以使用libcurl 库
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://www.oklink.com/api/v5/explorer/blockchain/info");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
更多的例子在这里 https://curl.haxx.se/libcurl/c/example.html
编译命令
g++ -o test test.cpp
1. 编译时报错
fatal error: curl/curl.h: No such file or directory
要安装curl库
sudo apt-get install libcurl4-openssl-dev
2. 安装curl库时报错
Depends: libcurl4 (= 7.58.0-2ubuntu3) but 7.58.0-2ubuntu3.13 is to be installed
把libcurl4给purge后再重新装就好了
apt-get purge libcurl4
apt-get install curl
最终编译成功,执行