在 Xamarin 中。我一直在尝试在我的 Web API 和我的 Xamarin 项目之间进行通信。这是我的控制器的代码:
// GET api/values
public List<string> Get()
{
List<string> values = new List<string>();
values.Add("Value 1");
values.Add("Value 2");
return values;
}
Run Code Online (Sandbox Code Playgroud)
这是我在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;
}
Run Code Online (Sandbox Code Playgroud)
每当我尝试运行我的 Android 应用程序和我的 Web API 应用程序时。我不断收到此异常:
Javax.Net.Ssl.SSLHandshakeException:
'java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.'
Run Code Online (Sandbox Code Playgroud)
我试过将它粘贴到我的MainActivity.cs 中,但它仍然不起作用。
ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, errors) …Run Code Online (Sandbox Code Playgroud)