1 #include <msp/core/application.h>
2 #include <msp/core/getopt.h>
3 #include <msp/debug/demangle.h>
4 #include <msp/http/client.h>
5 #include <msp/http/request.h>
6 #include <msp/http/response.h>
7 #include <msp/io/print.h>
12 class HttpGet: public RegisteredApplication<HttpGet>
19 HttpGet(int, char **);
23 void socket_error(const exception &);
26 HttpGet::HttpGet(int argc, char **argv):
30 getopt.add_option('v', "verbose", verbose, GetOpt::NO_ARG);
31 getopt.add_argument("url", url, GetOpt::REQUIRED_ARG);
38 client.signal_socket_error.connect(sigc::mem_fun(this, &HttpGet::socket_error));
42 IO::print("=== Sending request ===\n");
43 client.start_request(Http::Request::from_url(url));
44 IO::print(client.get_request()->str());
45 client.wait_response();
46 const Http::Response *response = client.get_response();
49 IO::print("=== Got response ===\n");
50 IO::print(response->str());
55 const Http::Response *response = client.get_url(url);
57 IO::print(response->get_content());
63 void HttpGet::socket_error(const exception &e)
65 IO::print("=== Error ===\n");
66 IO::print("%s\n", Debug::demangle(typeid(e).name()));
67 IO::print("%s\n", e.what());