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);
33 const vector<string> &args = getopt.get_args();
35 throw usage_error("No URL");
43 client.signal_socket_error.connect(sigc::mem_fun(this, &HttpGet::socket_error));
47 IO::print("=== Sending request ===\n");
48 client.start_request(Http::Request::from_url(url));
49 IO::print(client.get_request()->str());
50 client.wait_response();
51 const Http::Response *response = client.get_response();
54 IO::print("=== Got response ===\n");
55 IO::print(response->str());
60 const Http::Response *response = client.get_url(url);
62 IO::print(response->get_content());
68 void HttpGet::socket_error(const exception &e)
70 IO::print("=== Error ===\n");
71 IO::print("%s\n", Debug::demangle(typeid(e).name()));
72 IO::print("%s\n", e.what());