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;
}
And here is my GET request in my 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;
}
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.'
I've tried pasting this into my MainActivity.cs, but it still doesn't work.
ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, errors) => true;
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.