Answer the question
In order to leave comments, you need to log in
Why is the connection not established via SSL?
Hello! I decided to use SSL using the boost :: asio library, after looking at an example from the documentation, I tried to repeat it, I got an error on the socket.handshake operation, even copying the code I got the same error, but if I put sock.set_verify_mode (ssl: :verify_none) - then the code worked correctly, why?
The code:
ssl::context ctx(ssl::context::sslv23);
ctx.set_default_verify_paths();
// Open a socket and connect it to the remote host.
boost::asio::io_context io_context;
ssl_socket sock(io_context, ctx);
tcp::resolver resolver(io_context);
tcp::resolver::query query("ru.wikipedia.org", "https");
boost::asio::connect(sock.lowest_layer(), resolver.resolve(query));
sock.lowest_layer().set_option(tcp::no_delay(true));
// Perform SSL handshake and verify the remote host's
// certificate.
sock.set_verify_mode(ssl::verify_none); // Если прописать sock.set_verify_mode(ssl::verify_peer); - выпадает ошибка
sock.set_verify_callback(ssl::host_name_verification("en.wikipedia.org"));
sock.handshake(ssl_socket::client);
http::request<http::empty_body> request(http::verb::get, "/wiki/HTTP", 11);
request.set(http::field::host, "en.wikipedia.org");
request.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
http::write(sock, request);
flat_buffer buffer;
http::response<http::dynamic_body> response;
http::read(sock, buffer, response);
std::cout << buffers_to_string(response.body().data()) << std::endl;
sock.lowest_layer().shutdown(net::ip::tcp::socket::shutdown_both);
return 0;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question