I'm struggling to get my Windows 8 application to communicate with my test web API over SSL.
It seems that HttpClient/HttpClientHandler does not provide and option to ignore untrusted certificates like WebRequest enables you to (albeit in a "hacky" way with ServerCertificateValidationCallback
).
Any help would be much appreciated!
I found an example in this Kubernetes client where they were using X509VerificationFlags.AllowUnknownCertificateAuthority to trust self-signed self-signed root certificates. I slightly reworked their example to work with our own PEM encoded root certificates. Hopefully this helps someone.
Have a look at the WebRequestHandler Class and its ServerCertificateValidationCallback Property:
If you're attempting to do this in a .NET Standard library, here's a simple solution, with all of the risks of just returning
true
in your handler. I leave safety up to you.I found an example online which seems to work well:
First you create a new ICertificatePolicy
Then just use this prior to sending your http request like so:
http://www.terminally-incoherent.com/blog/2008/05/05/send-a-https-post-request-with-c/
Or you can use for the HttpClient in the
Windows.Web.Http
namespace:I don't have an answer, but I do have an alternative.
If you use Fiddler2 to monitor traffic AND enable HTTPS Decryption, your development environment will not complain. This will not work on WinRT devices, such as Microsoft Surface, because you cannot install standard apps on them. But your development Win8 computer will be fine.
To enable HTTPS encryption in Fiddler2, go to Tools > Fiddler Options > HTTPS (Tab) > Check "Decrypt HTTPS Traffic".
I'm going to keep my eye on this thread hoping for someone to have an elegant solution.