Xamarin:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚 [英] Xamarin: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found
问题描述
在Xamarin中.我一直在尝试在Web API和Xamarin项目之间进行通信.这是我的控制器的代码:
In Xamarin. I've been trying to make communications between my Web API and my Xamarin project. Here's the code for my controller:
// GET api/values
public List<string> Get()
{
List<string> values = new List<string>();
values.Add("Value 1");
values.Add("Value 2");
return values;
}
这是我的 MainPage.xaml.cs
public async void BindToListView()
{
HttpClient client = new HttpClient();
var response = await client.GetStringAsync("https://10.0.2.2:#####/api/Values");
var posts = JsonConvert.DeserializeObject<List<Posts>>(response);
lv.ItemsSource = posts;
}
每当我尝试同时运行我的Android应用程序和Web API应用程序时.我不断收到此异常:
Whenever I try to run both my Android application and my Web API Application. I keep getting this exception:
Javax.Net.Ssl.SSLHandshakeException:
'java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.'
我尝试将其粘贴到我的 MainActivity.cs 中,但仍然无法正常工作.
I've tried pasting this into my MainActivity.cs, but it still doesn't work.
ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, errors) => true;
几个月来我一直遇到这个问题,这让我发疯.我想念什么吗?我刚开始开发Xamarin应用程序,这是一个我似乎无法解决的问题.
I've been having this problem for months now, and its driving me crazy. Am I missing something? I'm fairly new in developing Xamarin applications, and this is a problem that I can't seem to resolve.
任何有关如何解决此问题的建议将不胜感激.感谢您抽出宝贵的时间阅读本文.
Any suggestions on how to resolve this problem will be greatly appreciated. Thanks for taking the time in reading this.
推荐答案
//Use this, it worked for me.
HttpClient client;
public class datastore {
var httpClientHandler = new HttpClientHandler();
httpClientHandler.ServerCertificateCustomValidationCallback =
(message, cert, chain, errors) => { return true; };
client = new HttpClient(httpClientHandler);
}
//... use the client to make request. it will bypass
//the ssl certificates verification.
这篇关于Xamarin:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!