我有以下curl代码,它向网站发出请求并从中检索数据,它运行良好,但我想将我的数据存储在字符串中而不是输出窗口中。任何想法?把CURL结果放入一个字符串而不是STDOUT?
#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://api.hostip.info/get_html.php?ip=xxx.xxx.xx.xxx");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
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;
}
看一看“CURLOPT_WRITEDATA”的描述,还有这个例子:https://curl.haxx.se/libcurl/c/getinmemory.html – moooeeeep 2016-02-16 14:37:59