我遇到的问题与卡萨布兰卡c++时,使用https在它的url

I am running into issues with Casablanca C++ when using urls with https in it

本文关键字:https 使用 url c++ 问题 遇到 卡萨布兰卡      更新时间:2023-10-16

我们使用Resource Owner Credentials来使用内部OAuth Svr获得访问令牌。如果url中不包含任何https,则一切正常,但当我在其中包含https时,一切都失败了。

我们用https部署了我们所有的站点:

后面是一个非常简单的失败代码。我没有任何线索,为什么我得到例外,如果我包括https在它。

try
{
    http_client api(U("https://172.27.12.207/AuthSvr"), m_http_config);
    ucout << "Requesting account information:" << std::endl;
    ucout << "Information: " << api.request(methods::GET, U("identity/.well-known/openid-configuration")).get().extract_json().get() << std::endl;
    //TestRestAPI().wait();
}
catch (...)
{
    ucout << "Unknown Error";
}

编辑

我处理异常捕获web::http::http_exception,我看到错误:

WinHttpSendRequest: 12175: A security error occurred

在尝试验证自签名证书时出现该问题。这通常出现在开发中,没有使用有效的证书,而是生成了一个动态证书。

可以通过禁用验证来解决这个问题。

web::http::client::http_client_config config;
config.set_validate_certificates(false);
auto client = std::make_shared<web::http::client::http_client>(U("https://localhost:8081/"), config);

请确保这只是在调试测试代码中完成的,而不是最终产品的一部分。

//创建一个HTTP请求句柄。shRequest = WinHttpOpenRequest (shConnect, L"GET", L"/robots.txt",空,WINHTTP_NO_REFERER,WINHTTP_DEFAULT_ACCEPT_TYPES,0);//WINHTTP_FLAG_SECURE);

在我的情况下,通过注释WINHTTP_FLAG_SECURE标志解决了类似的问题。