可以使用libcurl库来向网址php发起指定内容的get请求。下面是一个示例代码:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
    CURL *curl;
    CURLcode res;
    char url[100] = "http://example.com/phpfile.php?";
    char data[100] = "param1=value1&param2=value2";

    curl = curl_easy_init();
    if(curl) {
        strcat(url, data);
        curl_easy_setopt(curl, CURLOPT_URL, url);
        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;
}

其中,url是php文件的网址,data是要传递的参数,使用&符号分隔不同的参数。使用curl_easy_setopt函数设置请求的网址,然后使用curl_easy_perform函数执行请求,最后使用curl_easy_cleanup函数释放资源。

c语言怎么向网址php发起指定内容的get请求

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

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