我正在寻找 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/