cURL 获取响应

标签 c curl libcurl

我正在寻找 cURL 文档来阅读/理解。我在这里想做的是发布邮政编码并返回它是否有效。 到目前为止,这是我的功能(我设法从教程中收集到的内容)

int checkPostCode(char postCode[5])
{
    printf("checkPostCode\n");

    char uidPath[200] = "http://zim.cs.uow.edu.au/~dfs/cgi-bin/postcodes.cgi?pcode=";
    //Concatinate poth strings
    strcat (uidPath,postCode);
    //Output URl
    printf("%s \n ", uidPath);

    CURL *curl;
    CURLcode res;

    // Create our curl handle  
        curl = curl_easy_init();

    if (curl)  
        {  
        curl_easy_setopt(curl, CURLOPT_URL, uidPath);
        res = curl_easy_perform(curl);

        /* always cleanup */ 
        curl_easy_cleanup(curl);
    }

    return 0;
}

脚本返回"is"或“否”。 我只是不知道要在 if 语句中输入什么才能得到结果。

提前致谢:)。

最佳答案

听起来您想读取服务器的响应。为此,您需要启用选项 CURLOPT_READFUNCTION 并指定一个回调,该回调将从网络接收数据并将其存储在 char 数组中。

关于cURL 获取响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10354730/

相关文章:

c - 打印链表时,为什么原来的头指针没有变

c - 如何在c中使用指针合并排序字符串数组?

php - WordPress cURL 和 wp_remote_post

php - Curl:从 PHP 显示所有本地主机站点的 "Can' t 解析域名”错误

c++ - LIBCURL 中的简单 telnet 示例 - C++

php - 使用 cURL 针对 PHP 进行 C++ 身份验证

c - libcurl 中的 Json 字符串

c - 如何找到文件的完全限定路径名?

c - 文件指针是否导致代码中的段错误

带有 token 身份验证的 Java HTTP 请求