//1.初始化
CURL* curl = curl_easy_init();
//2.ssl认证
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, true);
//3.URL地址
curl_easy_setopt(curl, CURLOPT_URL, "服务器ip");
curl_easy_setopt(curl, CURLOPT_PORT, 8080);
//4.设置为非0表示本次操作为POST
curl_easy_setopt(curl, CURLOPT_POST, 1);
//5.Post数据
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "post数据");
//6.设置一个处理服务器响应的回调函数WriteDataCallback
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteDataCallback);
//7.对回调函数第四个参数进行设置
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res_data);
//8.向服务器发送请求
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK)
{
fprintf(stderr, "post perform error\n");
exit(1);
}
//9.释放内存
curl_easy_cleanup(curl);
curl_global_cleanup();
curl笔记
最新推荐文章于 2022-06-17 08:00:00 发布