Search code examples
c#androidxamarincertificatesslhandshakeexception

How can I install certificate for "Visual studio emulator for android"'s emulator?


I am working on a Xamarin Form that need to call httpclient to consume company's internal https REST api.

Unfortunately, it return with this error

Javax.Net.Ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

How can i resolve this?


Solution

  • To bypass certification validation you can:

    In Android Build options choose

    HttpClient Implementation: AndroidClientHandler
    SSL/TLS implementation: Default (Native TLS 1.2+)
    

    In MainActivity.cs add this

    ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, errors) => true;
    

    In the Httpclient init change this

    var httpClient = new HttpClient();
    

    To

    var httpClient = new HttpClient(new System.Net.Http.HttpClientHandler());