Question
Problem getting all Droplets
Hello DigitalOcean community :D
First of all I would like to thank you in advance for your time reading this and also for your help.
I am implementing a program who needs to make operations with DigitalOcean virtual machines, and it works most of what I have implemented.
The only thing that doesn’t work is when I try to get information about all droplets, which should be one of the easiest functions :S
https://developers.digitalocean.com/#list-all-droplets
The problem with this function is that when it performs the curl request, after a moment it just breaks and the application stops running, it doesn’t return any value.
My function to perform this request is the next one: (in c++)
void* curl = curl_easy_init();
std::string url = "https://api.digitalocean.com/v2/droplets/";
std::cout << "url=" << url << std::endl;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "deflate");
struct curl_slist *slist = NULL;
std::string authHeader = "Authorization: Bearer " + secretToken;
slist = curl_slist_append(slist, authHeader.c_str());
curl_slist_append(slist, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
std::stringstream out;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
cout << "This message is printed" << endl;
CURLcode res = curl_easy_perform(curl);
//THE PROGRAM STOPS HERE
cout << "This message is never printed" << endl;
/* Check for errors */
if (res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
return out.str();
I would appreciate a lot if somebody could see where is my mistake, since I have been a long time looking for it and I can’t see it. Or maybe I can get an example of getting all droplets, which I didn’t find while researching the community questions.
Thanks a lot in advance :-)
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×