ciao a tutti!
dovrei trasformare la risposta che ottengo con curl in string.
ho creato queste due funzioni, ma quando richiamo la funzione il programma fallisce.
nessun errore in compilazione:
codice:
void Read::readUltimeEntrateUscite(string file) {
curl = curl_easy_init();
curl_slist_append(headers, "Accept: application/json");
curl_slist_append(headers, "Content-Type: application/json");
curl_slist_append(headers, "charset: utf-8");
if (curl) {
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, url.append(file).c_str());
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &Read::curlToString);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
res = curl_easy_perform(curl);
if (res == CURLE_OK) {
cout << response << endl;
}
}
curl_easy_cleanup(curl);
}
int Read::curlToString(char *data, size_t size, size_t nmemb, string *buffer) {
int result = 0;
if (buffer != NULL) {
buffer->append(data, size * nmemb);
result = size * nmemb;
}
return result;
}
il programma si blocca quando questa riga non è commentata:
codice:
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &Read::curlToString);
penso che ci sia un errore nella funzione di callback.
avete qualche suggerimento??