在C中访问URL

在C中访问URL,c,web-services,sockets,url,C,Web Services,Sockets,Url,我知道这是一个非常普遍的问题,相信我,我很抱歉。然而,我现在正处于时间紧迫期 我需要什么: 我需要通过GET请求将数据发送到web服务器 比如: http://example.com/?info=%s 该网站很可能使用cloudflare进行设置,因此无法使用直接IP访问(即gethostbynam) 我需要像URL“访问者”这样简单的东西。使用签出此 根据需要传递给服务器的参数修改URL字符串。如doukremnt和CodeArtister所述,使用以下代码 #include <

我知道这是一个非常普遍的问题,相信我,我很抱歉。然而,我现在正处于时间紧迫期

我需要什么:
我需要通过GET请求将数据发送到web服务器

比如:

http://example.com/?info=%s
该网站很可能使用cloudflare进行设置,因此无法使用直接IP访问(即gethostbynam)

我需要像URL“访问者”这样简单的东西。

使用签出此


根据需要传递给服务器的参数修改URL字符串。

如doukremnt和CodeArtister所述,使用以下代码

    #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://example.com");
        /* example.com is redirected, so we tell libcurl to follow redirection */ 
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

        /* Perform the request, res will get the return code */ 
        res = curl_easy_perform(curl);
        /* Check for errors */ 
        if(res != CURLE_OK)
          fprintf(stderr, "curl_easy_perform() failed: %s\n",
                  curl_easy_strerror(res));

        /* always cleanup */ 
        curl_easy_cleanup(curl);
      }
      return 0;
    }
#包括
#包括
内部主(空)
{
卷曲*卷曲;
卷曲编码;
curl=curl_easy_init();
if(curl){
curl\u easy\u setopt(curl,CURLOPT\u URL,“http://example.com");
/*com被重定向,因此我们告诉libcurl遵循重定向*/
卷曲位置(卷曲,卷曲位置,1L);
/*执行请求时,res将获得返回代码*/
res=旋度(curl)\u容易执行(curl);
/*检查错误*/
如果(res!=卷曲(OK)
fprintf(stderr,“curl\u easy\u perform()失败:%s\n”,
卷曲(容易的);
/*始终清理*/
旋度\轻松\清洁(旋度);
}
返回0;
}
libcurl
()是事实上的标准,是用C编写的。