Created
May 12, 2017 11:47
-
-
Save svedi/815be537c3d02a00a171d0417e7160f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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