Created
December 2, 2017 14:32
-
-
Save tcoppex/bf382d02dbb15c05a7df2f96a2ad322d to your computer and use it in GitHub Desktop.
Simple async case for 'curl for people'
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 <cpr/cpr.h> // https://github.com/whoshuu/cpr | |
#include <iostream> | |
static const char* sURL = "https://www.google.fr"; | |
void async_result() { | |
auto fr = cpr::GetAsync( | |
cpr::Url{sURL} | |
, cpr::VerifySsl{false} | |
); | |
auto r = fr.get(); | |
std::cout << r.status_code << std::endl | |
<< r.header["content-type"] << std::endl | |
<< r.text << std::endl | |
; | |
} | |
void callback_result() { | |
auto cb = cpr::GetCallback( | |
[](cpr::Response r) { return r.text; } | |
, cpr::Url{sURL} | |
, cpr::VerifySsl{false} | |
); | |
std::cout << "Waiting"; | |
while (cb.wait_for(std::chrono::seconds(0)) != std::future_status::ready) { | |
std::cout << "."; | |
} | |
std::cout << std::endl << cb.get() << std::endl; | |
} | |
int main(int argc, char** argv) { | |
callback_result(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment