curl的安装及使用

1.centos7 下curl 的安装命令:yum -y install curl
yum -y install curl-devel
2.使用curl的方法:
#include
#include <curl/curl.h>
#include
#include

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, “POST”);
curl_easy_setopt(curl, CURLOPT_URL, “http://guandao.iweihu.com.cn/api/push/users”);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, “https”);
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, “Content-Type: application/json”);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = “{ }\n ]\n}”;
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}

猜你喜欢

转载自blog.csdn.net/weixin_44881103/article/details/104553848