Im using mingw64.
How can I make https-request using boost beast lib?
I got code below and it works, but I recieve answer: "400 The plain HTTP request was sent to HTTPS port"
What should I complete here to make https request? OpenSSL is installed.
#include <boost/beast/root_certificates.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <iostream>
void boost_request()
{
namespace http = boost::beast::http;
const std::string host = "api.vk.com"; //"scooterlabs.com";
const std::string target = "/method/wall.get?&owner_id=-***&access_token=***&v=5.61&count=1000"; //"/echo?input=test";
boost::asio::io_context ioc;
boost::asio::ip::tcp::resolver resolver(ioc);
boost::asio::ip::tcp::socket socket(ioc);
boost::asio::ip::tcp::resolver::query query("api.vk.com", "https");
boost::asio::connect(socket.lowest_layer(), resolver.resolve(query));
socket.lowest_layer().set_option(boost::asio::ip::tcp::no_delay(true));
http::request<http::string_body> req(http::verb::get, target, 11);
req.set(http::field::host, host);
req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
http::write(socket, req);
boost::beast::flat_buffer buffer;
http::response<http::dynamic_body> res;
http::read(socket, buffer, res);
std::cout << res << std::endl;
socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
}
int main()
{
boost_request();
}