我正在使用带有 https url 的 cpprestsdk“Casablanca”主分支,它在 Windows 和 osx 上都有效,但是当我在 linux 上运行它时,我收到“错误是 ssl 握手”
C++ exception with description "Error in SSL handshake" thrown in the test body.
我尝试使用 Firefox 打开这个 url,它有效。
当我将它与 http url 一起使用时,它工作正常我检查了代码,我在一个名为“http_client_asio.cpp”的文件中找到了这条消息
void write_request()
{
// Only perform handshake if a TLS connection and not being reused.
if (m_connection->is_ssl() && !m_connection->is_reused())
{
const auto weakCtx = std::weak_ptr<asio_context>(shared_from_this());
m_connection->async_handshake(boost::asio::ssl::stream_base::client,
m_http_client->client_config(),
m_http_client->base_uri().host(),
boost::bind(&asio_context::handle_handshake, shared_from_this(), boost::asio::placeholders::error),
// Use a weak_ptr since the verify_callback is stored until the connection is destroyed.
// This avoids creating a circular reference since we pool connection objects.
[weakCtx](bool preverified, boost::asio::ssl::verify_context &verify_context)
{
auto this_request = weakCtx.lock();
if(this_request)
{
return this_request->handle_cert_verification(preverified, verify_context);
}
return false;
});
}
else
{
m_connection->async_write(m_body_buf, boost::bind(&asio_context::handle_write_headers, shared_from_this(), boost::asio::placeholders::error));
}
}
void handle_handshake(const boost::system::error_code& ec)
{
if (!ec)
{
m_connection->async_write(m_body_buf, boost::bind(&asio_context::handle_write_headers, shared_from_this(), boost::asio::placeholders::error));
}
else
{
report_error("Error in SSL handshake", ec, httpclient_errorcode_context::handshake);
}
}
在客户端我像这样创建了http客户端
http_client client(U("https://www.bing.com/"));
我该如何解决这个错误?