Add a base class for http async clients; refine examples.

This commit is contained in:
Chunting Gu
2019-02-12 17:06:26 +08:00
parent 9ecec5de0b
commit 43eaf90621
43 changed files with 803 additions and 507 deletions
+4
View File
@@ -0,0 +1,4 @@
add_executable(http_client main.cc)
target_link_libraries(http_client webcc ${Boost_LIBRARIES})
target_link_libraries(http_client "${CMAKE_THREAD_LIBS_INIT}")
+29
View File
@@ -0,0 +1,29 @@
#include <iostream>
#include "webcc/http_client.h"
#include "webcc/logger.h"
static void PrintError(const webcc::HttpClient& client) {
std::cout << webcc::DescribeError(client.error());
if (client.timed_out()) {
std::cout << " (timed out)";
}
std::cout << std::endl;
}
int main() {
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
auto request = webcc::HttpRequest::Make(webcc::kHttpGet, "/get",
"httpbin.org");
webcc::HttpClient client;
if (client.Request(*request)) {
std::cout << client.response_content() << std::endl;
} else {
PrintError(client);
}
return 0;
}