'System.Net.WebException: Error: TrustFailure (Authentication failed, see inner exception.)

While making a request to HTTPS server, I am getting following error. Request works with HTTP.

{System.Net.WebException: Error: TrustFailure (Authentication failed, see inner exception.) ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> Mono.Btls.MonoBtlsException: Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED

I have set HTTPClientHandler to Android and TLS/SSL Implementation to Native TLD 1.2+ in Android settings.



Solution 1:[1]

This is how I did it using WebClient and than just need add ServerCertificateValidationCallback

var uri = new UriBuilder("https://url/v3/0").Uri;
var client = new WebClient();
ServicePointManager.ServerCertificateValidationCallback = new
    RemoteCertificateValidationCallback
    (
       delegate { return true; }
    );    
var content = client.DownloadString(uri);

Solution 2:[2]

I solved this by adding ServerCertificateCustomValidationCallback property to HttpWebRequest object like this.

HttpWebRequest request = new HttpWebRequest(new Uri());
request.ServerCertificateCustomValidationCallback = delegate {return true;}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 R15
Solution 2 Ali Raza