C语言GET请求示例代码及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, 'http://www.example.com'); res = curl_easy_perform(curl); if(res != CURLE_OK) fprintf(stderr, 'curl_easy_perform() failed: %s\n', curl_easy_strerror(res)); curl_easy_cleanup(curl); } return 0; }
该代码使用了libcurl库,它提供了一个简单易用的API,用于发送HTTP请求。在该示例中,我们创建了一个CURL对象,并设置了请求的URL。然后,我们执行了请求,并检查了返回值是否为CURLE_OK,以确保请求成功。最后,我们清理了CURL对象。
原文地址: https://www.cveoy.top/t/topic/l5qF 著作权归作者所有。请勿转载和采集!