Hi,
I need some help with tracking down why this is happening. I am testing on real devices, Galaxy 7 and iPhone7
I have a cross platform - shared not PCL - app which is trying to connect to an Https site.
I have tested the following code with another https site and it works fine, but when connecting to the target site - which is an Azure site if that makes a difference - it fails silently on Android on the statement
var response = await client.GetAsync(new Uri(url))
and on iOS I do at least get a catch failure with the following not very helpful info:
"An SSL error has occurred and a secure connection to the server cannot be made."
The other https site is with zerobounace, again I cannot publish the link due to this site blocking me posting links, but it works perfectly.
The following code has been minimised to try and detect the error. Both the Android and iOS have been set to tls1.2 as described in the Xamarin documentation - the service point setting below has been used to try and solve the problem, and the certificate check I am assured overcomes certificate issues.
Regarding potential certificate issues, I built a simple MVC web app to test and the following code works perfectly so there is likely something in Xamarin not set correctly or something to do with the Azure site, but I am at a loss after spending days looking at this.
public async Task LocationButtonClicked(object sender, EventArgs args)
{
string url = "**This is a valid API link, but this support site is stopping me posting links **";
try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds( 15);
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
var response = await client.GetAsync(new Uri(url));
var content = "failed";
if (response.IsSuccessStatusCode)
{
content = await response.Content.ReadAsStringAsync();
//Items = JsonConvert.DeserializeObject<List<TodoItem>>(content);
}
else
{
var a = "halt";
}
}
catch (Exception e)
{
throw;
}
}
public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
}