Last active
December 10, 2016 02:50
-
-
Save Alexhuszagh/e3c534f7cf317c5f88102f1307113622 to your computer and use it in GitHub Desktop.
Lattice vs. cURL
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 <curl/curl.h> | |
#include <iostream> | |
int main(void) | |
{ | |
CURL *curl; | |
CURLcode res; | |
curl_global_init(CURL_GLOBAL_ALL); | |
curl = curl_easy_init(); | |
if(curl) { | |
curl_easy_setopt(curl, CURLOPT_URL, "http://httpbin.org/basic-auth/user/pass"); | |
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); | |
curl_easy_setopt(curl, CURLOPT_USERPWD, "user:pass"); | |
curl_easy_setopt(hnd, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC); | |
curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/7.51.0"); | |
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5); | |
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1); | |
res = curl_easy_perform(curl); | |
if(res != CURLE_OK) { | |
std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl; | |
} else { | |
std::string response; | |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); | |
std::cout << response << std::endl; | |
} | |
curl_easy_cleanup(curl); | |
} | |
curl_global_cleanup(); | |
return 0; | |
} |
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 <lattice.hpp> | |
#include <iostream> | |
int main(int argc, char *argv[]) | |
{ | |
lattice::Url url = {"http://httpbin.org/basic-auth/user/pass"}; | |
lattice::Authentication auth = {"user", "pass"}; | |
auto response = lattice::Get(url, auth); | |
std::cout << response.body() << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment