我有以下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