forked from cpp-netlib/cpp-netlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_headers.cpp
More file actions
43 lines (35 loc) · 1.23 KB
/
Copy pathread_headers.cpp
File metadata and controls
43 lines (35 loc) · 1.23 KB
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
35
36
37
38
39
40
41
42
43
// Copyright (C) 2013 by Glyn Matthews
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <network/http/client.hpp>
#include <iostream>
namespace http = network::http;
int
main(int argc, char *argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " url" << std::endl;
return 1;
}
try {
http::client client;
http::request request{network::uri{std::string{argv[1]}}};
request.version("1.0");
request.append_header("Connection", "close");
request.append_header("User-Agent", "cpp-netlib read_headers example");
auto future_response = client.head(request);
auto response = future_response.get();
std::cout << "HTTP version: " << response.version() << std::endl;
std::cout << "HTTP status: " << static_cast<int>(response.status()) << std::endl;
std::cout << "HTTP status message: " << response.status_message() << std::endl;
std::cout << std::endl;
for (auto header : response.headers()) {
std::cout << header.first << ": " << header.second << std::endl;
}
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}