【发布时间】:2016-02-22 18:59:52
【问题描述】:
我正在使用带有 https url 的 cpprestsdk "Casablanca" master 分支,它在 windows 和 osx 上都可以工作,但是当我在 linux 上运行它时,我收到 "Error is ssl handshake"
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/"));
我该如何解决这个错误?
【问题讨论】:
-
能否添加断点并添加有关导致该消息的
ec对象的更多信息?另外,你试过其他网站吗?如果您可以通过 http 站点重现该问题,则可以尝试使用 wireshark 检查网络通信。
标签: c++ openssl casablanca