Created
June 16, 2018 12:00
-
-
Save addisaden/dcd87269c071a099610f9669c2f7aaf3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <iostream> | |
#include <string> | |
#include <curl/curl.h> | |
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp | |
{ | |
((std::string*)userp)->append((char*)contents, size * nmemb); | |
return size * nmemb; | |
} | |
int main () | |
{ | |
CURL *curl; | |
CURLcode res; | |
std::string content; | |
curl_global_init(CURL_GLOBAL_DEFAULT); | |
curl = curl_easy_init(); | |
if (curl) | |
{ | |
curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.de/"); | |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); | |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &content); | |
res = curl_easy_perform(curl); | |
curl_easy_cleanup(curl); | |
} | |
curl_global_cleanup(); | |
std::cout << content << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment