Https error 12175 occurred even config.set_validate_certificates(false) has been invoked.

Apr 1, 2016 at 7:14 AM
Edited Apr 1, 2016 at 8:15 AM
Hi,

I am trying Cpp Rest SDK (Version: 2.8.0) on Win8 X64 with VS2013 to POST a request to a remote server.
It works fine if scheme is set as http, but fails when is set as https with error below:

Exception:WinHttpSendRequest: 12175: A security error occured

I have tried set_validate_certificates(false) and also reinstalled REST SDK. But the same error comes out.

By the way, i installed REST SDK with NuGet.

My code is as below:
void BuildUConnectRequest(uri_builder &builder, http_request &request,
                                        http_client_config &clientConfig)
{
    builder.set_scheme(L"https");
    builder.set_host(LPCWSTR(g_Param.strIP));
    builder.set_port(g_Param.usPort);
    builder.set_path(L"mySvc/connect");

    request.set_method(methods::POST);
    request.headers().add(L"Content-Type", L"application/json; charset=UTF-8");
    
    clientConfig.set_validate_certificates(false);

    json::value reqObj;
    reqObj[L"locale"] = json::value::string(U("cn"));
    reqObj[L"servicetype"] = json::value::number(g_Param.usSvcType);

    request.set_body(reqObj);

    return;
}

void HandleConnectResponse(http_response &response)
{
    // Do something here
    return;
}

void ConnectServer()
{
    uri_builder uriBuiler;
    http_request request;
    http_client_config clientConfig;
    
    BuildUConnectRequest(uriBuiler, request, clientConfig);

    http_client client(uriBuiler.to_uri(), clientConfig);

    pplx::task<void> requestTask =
        client.request(request)
        .then([&](http_response response)
    {
        HandleConnectResponse(response);
    });

    try
    {
        requestTask.wait();
        return;
    }
    catch (const std::exception& e)
    {
        CString strExp;
        strExp.Format(_T("Exception: %s"), conversions::to_utf16string(e.what()));
        AfxMessageBox(strExp);
        return;
    }
}
Thanks and wish your reply.
Apr 19, 2016 at 10:57 AM
who can suggest me the way to attach Certificate to the https request from client?