I want to explicitly set the scheme (http vs https), the host and the port number when using Boost ASIO's tcp::iostream
class. I see plenty of examples where scheme and host are used together, but not with port, too. I get the impression that the port is being determined automatically. However, I need to set it explicitly.
Asked
Active
Viewed 787 times
0

Sam Miller
- 23,808
- 4
- 67
- 87

Travis Parks
- 8,435
- 12
- 52
- 85
1 Answers
1
First, the iostream
constructor takes parameters equivalent to a resolver::query
as the documentation clearly states. The first argument is the host, the second is the service (also known as port)
basic_resolver_query(
const std::string & host,
const std::string & service,
resolver_query_base::flags resolve_flags = address_configured);
Second, the boost:asio::ip::tcp::iostream
class does not support a scheme, it is strictly for TCP streams as the type implies. It does not perform SSL handshaking or encryption, so no HTTPS. If you desire additional functionality you will need to implement it yourself, likely using the boost::iostream
library as described in this question.

Community
- 1
- 1

Sam Miller
- 23,808
- 4
- 67
- 87
-
Thanks for helping me distinguish between the protocol and the application layer. I think I jumped to conclusions when "https" urls didn't work the same way "http" did. My code is going to have to look at the scheme to determine what it needs to do. – Travis Parks Sep 30 '12 at 16:14
-
On an interesting side note, passing "http" or whatever to the ctor/connect has an effect on the code. My guess is asio is looking up the standard port for me. – Travis Parks Sep 30 '12 at 16:17
-
@travis thst is the expected behavior when resolving a service name such as http, ftp, etc. – Sam Miller Sep 30 '12 at 17:34