cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

http_client always fails when server supports (but not requires) client certificates

Open weltkante opened this issue 8 years ago • 1 comments

I want to use http_client to send WNS notifications from an IoT device, but for now I'm developing the code on a windows 10 machine so I can properly debug everything. I can properly authenticate with WNS but when I try to send a notification I'm getting a http_exception ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED (12044). The same requests header/body goes through cleanly when issued from C# code without having to do anything about client certificates, so I believe your implementation has a bug.

After some trial and error I figured out that I could disable client certificates explicitely with the following code:

web::http::client::http_client_config config;
config.set_nativehandle_options([](web::http::client::native_handle handle) {
    WinHttpSetOption(handle, WINHTTP_OPTION_CLIENT_CERT_CONTEXT, WINHTTP_NO_CLIENT_CERT_CONTEXT, 0);
});

This allows the request to go through cleanly. Since your http_client class does not support client certificates out of the box I believe you should configure this by default and not require callers to have to configure every request manually.

weltkante avatar Dec 31 '17 13:12 weltkante

You made my day ;)

hypetsch avatar Sep 12 '24 07:09 hypetsch