qicosmos / cinatra

modern c++(c++20), cross-platform, header-only, easy to use http framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ssl

51bitquant opened this issue · comments

请求https的地址,一直提示这个错误,请问下,SSL请求需要啥配置吗?

    using namespace cinatra;
    coro_http_client client{};
    client.init_ssl("../../include/cinatra", "server.crt");
    auto data = client.get("https://www.bing.com");
    std::cout << data.resp_body << "\n";
<title>400 The plain HTTP request was sent to HTTPS port</title>

400 Bad Request

The plain HTTP request was sent to HTTPS port

应该是缺少证书文件,你直接把init_ssl 参数去掉试一下,直接init_ssl();

 client.init_ssl("../../include/cinatra", "server.crt");

这个server.crt 文件还是可以找到的,在项目中。

你先把参数去掉试一下再说。

去掉参数提示: handle failed tlsv1 alert internal error (SSL routines)

cmake 里把ENABLE_SSL 设置为ON

SET(ENABLE_GZIP ON)
SET(ENABLE_SSL ON)
SET(ENABLE_CLIENT_SSL ON)
这个之前已经设置好了,还是不行。

你跑的是tests是吧,tests的话要tests 里面的cmakelists中的CINATRA_ENABLE_SSL 改成ON

先清理一下cmake

我本地测试这个case 返回的是302重定向,是正常的。

int main() {
using namespace cinatra;
coro_http_client client{};
client.init_ssl("", "", asio::ssl::verify_peer, "connecting domain");
auto response = client.get("https://www.domain.com");
std::cout << response.status << std::endl;
std::cout << response.resp_body << std::endl;

return 0;

}