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

那年仲夏 提交于 2021-01-29 07:00:49

问题


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?


回答1:


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());


来源:https://stackoverflow.com/questions/56597401/how-can-i-install-certificate-for-visual-studio-emulator-for-androids-emulato

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!