File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed
Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 11set (EXAMPLE_SOURCES echo_server.cpp daytime_client.cpp threadpool.cpp time_client.cpp)
22
3+ if (WITH_HTTP)
4+ set (EXAMPLE_SOURCES ${EXAMPLE_SOURCES} http_client.cpp)
5+ endif ()
6+
37foreach (examplesource ${EXAMPLE_SOURCES} )
48 string (REPLACE ".cpp" "" examplename ${examplesource} )
59 add_executable (${examplename} ${examplesource} )
Original file line number Diff line number Diff line change 1- //
2- // Created by lpcvoid on 25.12.22.
3- //
1+ #include " ../src/netlib.hpp"
2+ #include " ../src/http/client.hpp"
3+ #include " ../src/http/http.hpp"
4+ #include < csignal>
5+ #include < iomanip>
6+ #include < iostream>
7+
8+
9+ void exit_handler (int s){
10+ std::cout << " Goodbye!" << std::endl;
11+ exit (EXIT_SUCCESS);
12+ }
13+
14+ int main (int argc, char ** argv)
15+ {
16+ netlib::http::http_client client;
17+
18+ auto res = client.get (" http://example.com" );
19+
20+ if (res.second ) {
21+ std::cerr << " Error: " << res.second .message () << std::endl;
22+ exit (1 );
23+ }
24+
25+ std::cout << " Got HTTP response: " << res.first ->response_code <<
26+ " , version " << res.first ->version .first << " ." << res.first ->version .second << std::endl;
27+ std::cout << " Header entries:" << std::endl;
28+ std::for_each (res.first ->headers .begin (), res.first ->headers .end (), [](auto header_entry) {
29+ std::cout << header_entry.first << " = " << header_entry.second << std::endl;
30+ });
31+ std::cout << " Body:" << std::endl;
32+ std::cout << res.first .value ().body << std::endl;
33+
34+ signal (SIGINT, exit_handler);
35+ }
You can’t perform that action at this time.
0 commit comments