curl-users
how to set options to get return content ?
Date: Fri, 2 Nov 2012 01:08:23 +0100
Hello everyone,
I am trying to use cURL to apply request to twitter api. For example : https://api.twitter.com/1/users/lookup.json?screen_name=twitterapi,twitter
I want to save the return content (the json object) to memory, like a char* object. here's what I write:
CURL *curl;
CURLcode res;
void* data;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.twitter.com/1/users/lookup.json?screen_name=twitterapi,twitter");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);
//curl_easy_setopt(curl, CURLINFO_PRIVATE, data);
printf("before perform.\n");
res = curl_easy_perform(curl);
char *ct;
curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
printf("ct is : %s\n", ct);
printf("data is : %s\n", (char*)data);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
However every time the JSON object is printed in stdout and I can't get it in memory.
Is there some method to solve this ?
Thanks.
LIU Liang
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-11-02