The boost asio official documentation gives two examples of making HTTP requests and using SSL for a connection. However, none of these examples do a HTTPS GET request.
In other words, if you want to make a HTTP GET request over a secure connection, you need to combine the two examples.
The links to the examples are http client and ssl client.
Let’s see the difference between a HTTP client and a HTTPS client.
First, for the HTTP client the asio “flow”, as per the http client example in the link above, is as follows:
- Resolve
- Connect
- Send request
- Receive response (process status, headers, body, etc.)
For a HTTPS client, a few modifications are required. First, regarding the code, one needs an ssl context boost::asio::ssl::context and the socket must support ssl. I’ve used boost::asio::ssl::stream<boost::asio::ip::tcp::socket>.
The application flow changes also:
- Resolve (use https for the resolve query)
- Certificate verification
- Connect
- SSL handshake (via async_handshake)
- Send request
- Receive response (process status, headers, body, etc.)
So, a few additional steps are required to implement the SSL handshake and send requests only after the handshake is completed.
A full source code example of a HTTPS client is availale here: https://github.com/alexandruc/SimpleHttpsClient