Skip to content

Instantly share code, notes, and snippets.

@svedi
Created May 12, 2017 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svedi/815be537c3d02a00a171d0417e7160f3 to your computer and use it in GitHub Desktop.
Save svedi/815be537c3d02a00a171d0417e7160f3 to your computer and use it in GitHub Desktop.
#include <curl/curl.h>
size_t
handle_response(char * ptr, size_t size, size_t nmemb, void *userdata)
{
std::string current{ptr, size*nmemb};
std::string *response = (std::string *)userdata;
*response += current;
return size*nmemb;
}
int main() {
CURL *curl = curl_easy_init();
std::string response;
curl_easy_setopt(curl, CURLOPT_URL, "http://google.com/");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, handle_response);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment