以下是一个简单的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, "https://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;
}

这个代码使用了curl_easy_init()函数初始化一个CURL对象,然后通过curl_easy_setopt()函数设置请求的URL,最后使用curl_easy_perform()函数执行请求并获得响应。如果请求失败,会输出错误信息。

c语言get请求代码

原文地址: https://www.cveoy.top/t/topic/M9r 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录