Tôi muốn lưu trữ kết quả của hàm curl này trong một biến, làm thế nào tôi có thể làm như vậy?C libcurl lấy đầu ra thành một chuỗi
#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, "curl.haxx.se");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
cảm ơn, tôi giải quyết nó như thế này:
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
function_pt(void *ptr, size_t size, size_t nmemb, void *stream){
printf("%d", atoi(ptr));
}
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, function_pt);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
system("pause");
return 0;
}
Chỉ cần chỉ ra giải pháp của bạn trong function_pt() bạn đang chuyển đổi chuỗi trong ptr thành số nguyên để chuyển đổi chuỗi đó thành chuỗi ở đầu ra. Bạn có thể xuất chuỗi trực tiếp (và xem câu trả lời đầy đủ). – zzz
đây là liên kết đến ví dụ cURL http://curl.haxx.se/libcurl/c/getinmemory.html – lafferc
'CURLcode res;' không được sử dụng – fnc12