Hello!
I tried to use libcurl in my application.
I took HelloWorld application and replaced handle of the button:
void HelloWorld::menuCloseCallback(CCObject* pSender) {
std::string url("http://www.google.com/calendar/feeds/developer-calendar@google.com/public/full?alt=json");
CURL *curl;
CURLcode res;
std::string buffer;
curl_global_init( CURL_GLOBAL_ALL );
curl = curl_easy_init();
if( curl )
{
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); // tell us what is happening
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HelloWorld::writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK && !buffer.empty()) {
std::cout<
and added writer:
size_t HelloWorld::writer( char *data, size_t size, size_t nmemb, std::string *writerData ) {
size_t retValue = 0;
if(writerData != NULL)
{
writerData->append(data, size * nmemb);
retValue = size * nmemb;
}
return retValue;
}
Thanks to guys from: http://www.cocos2d-x.org/boards/6/topics/6944.
But code CCLog(“buffer: %s”, buffer.c_str()) raise error: EXC_BAD_ACCESS.
Unfortunately in curl test I did not find code working with buffer, only with result code.
What do I do wrong? What kind of magic should I use to make it working?
Thank you.