| 159 | //------------------------------------------------------------------------------ |
| 160 | |
| 161 | int main(int argc, char** argv) |
| 162 | { |
| 163 | // Check command line arguments. |
| 164 | if(argc != 4 && argc != 5) |
| 165 | { |
| 166 | std::cerr << |
| 167 | "Usage: http-client-async <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" << |
| 168 | "Example:\n" << |
| 169 | " http-client-async www.example.com 80 /\n" << |
| 170 | " http-client-async www.example.com 80 / 1.0\n"; |
| 171 | return EXIT_FAILURE; |
| 172 | } |
| 173 | auto const host = argv[1]; |
| 174 | auto const port = argv[2]; |
| 175 | auto const target = argv[3]; |
| 176 | int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11; |
| 177 | |
| 178 | // The io_context is required for all I/O |
| 179 | net::io_context ioc; |
| 180 | |
| 181 | // Launch the asynchronous operation |
| 182 | std::make_shared<session>(ioc)->run(host, port, target, version); |
| 183 | |
| 184 | // Run the I/O service. The call will return when |
| 185 | // the get operation is complete. |
| 186 | ioc.run(); |
| 187 | |
| 188 | return EXIT_SUCCESS; |
| 189 | } |