-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhttp_client.cpp
More file actions
34 lines (28 loc) · 1023 Bytes
/
http_client.cpp
File metadata and controls
34 lines (28 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "../src/netlib.hpp"
#include "../src/http/client.hpp"
#include "../src/http/http.hpp"
#include <csignal>
#include <iomanip>
#include <iostream>
void exit_handler(int s){
std::cout << "Goodbye!" << std::endl;
exit(EXIT_SUCCESS);
}
int main(int argc, char** argv)
{
netlib::http::http_client client;
auto res = client.get("http://example.com");
if (res.second) {
std::cerr << "Error: " << res.second.message() << std::endl;
exit(1);
}
std::cout << "Got HTTP response: " << res.first->response_code <<
", version " << res.first->version.first << "." << res.first->version.second << std::endl;
std::cout << "Header entries:" << std::endl;
std::for_each(res.first->headers.begin(), res.first->headers.end(), [](auto header_entry) {
std::cout << header_entry.first << " = " << header_entry.second << std::endl;
});
std::cout << "Body:" << std::endl;
std::cout << res.first.value().body << std::endl;
signal(SIGINT, exit_handler);
}