如何为“适用于Android的Visual Studio仿真器"的仿真器安装证书? [英] How can I install certificate for "Visual studio emulator for android"'s emulator?

查看:80
本文介绍了如何为“适用于Android的Visual Studio仿真器"的仿真器安装证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 Xamarin表单,该表单需要调用 httpclient 来使用公司内部的https REST api.

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.

我该如何解决?

推荐答案

要绕过认证验证,您可以:

To bypass certification validation you can:

在"Android构建"选项中选择

In Android Build options choose

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

在MainActivity.cs中添加此

In MainActivity.cs add this

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

在Httpclient初始化中更改此

In the Httpclient init change this

var httpClient = new HttpClient();

收件人

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

这篇关于如何为“适用于Android的Visual Studio仿真器"的仿真器安装证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆