在 Xamarin 中。我一直在尝试在我的 Web API 和我的 Xamarin 项目之间进行通信。这是我的 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
中的 GET 请求 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 应用程序时。我不断收到此异常:
Javax.Net.Ssl.SSLHandshakeException:
'java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.'
我尝试将其粘贴到我的 MainActivity.cs 中,但仍然无法正常工作。
ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, errors) => true;
几个月来我一直有这个问题,这让我发疯了。我错过了什么吗?我是开发 Xamarin 应用程序的新手,这是一个我似乎无法解决的问题。
任何有关如何解决此问题的建议将不胜感激。感谢您花时间阅读本文。
最佳答案
//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.
关于c# - Xamarin:java.security.cert.CertPathValidatorException:找不到证书路径的信任 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58376095/