curl-users
AW: how to set options to get return content ?
From: <Alexander.Elgert_at_external.t-systems.com>
Date: Fri, 2 Nov 2012 11:28:53 +0100
Date: Fri, 2 Nov 2012 11:28:53 +0100
Hello,
I did this job a few days ago, just look at this (complete) example:
http://curl.haxx.se/libcurl/c/getinmemory.html
You have to set this two CURLOPTions:
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); /* send all data to this function */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
The first one is to set the handler function, the second one to pass the struct, which holds the char* and its size.
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
Greetings,
Alexander
-- Deutsche Telekom AG Seamless ICT Security Infrastructure & Management im Auftrag T-Systems International GmbH Dipl. Inf Alexander Elgert Langwadener Strasse 17 64625 Bensheim +49 176 22 717 661 (Mobil) +49 671 83419-12 (Tel) +49 671 83419-30 (Fax) E-Mail: alexander.elgert_at_gmx.de ________________________________________ Von: curl-users [curl-users-bounces_at_cool.haxx.se] im Auftrag von Liang LIU [mmhancxt_at_gmail.com] Gesendet: Freitag, 2. November 2012 01:08 An: curl-users_at_cool.haxx.se Betreff: how to set options to get return content ? 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.htmlReceived on 2012-11-02