Maybe these could help you:
SSL connection could not be established on android prior 9
Here is my scenario:
- ASP.NET Core API server on azure using https
- MAUI app, the android apk supporting from android 5.0+
- installed on various devices:
- huawei with android 10 on two devices: works perfectly
- pixel 2 with android 11: works perfectly
- pixel 4 with android 13: works perfectly
- nokia with android 11: works perfectly
- some old android 5.1 and other android 10 does not work
- emulator with android 7 or 8: doesn't work
So same build, works on most of the devices, doesn't work on others. Exception I get on android 5.1 is:
The ssl connection could not be established. See inner exception.
And in the inner exception I get:
System.PlatformNotSupportedExcetpion: Setting an SNI hostname is not supported on this API level.
I assume that this may be because android 5 is really old. However, I managed to get another inner exception when running on android 7 and 8 emulators.
The ssl connection could not be established. See inner exception.
However the inner exception is different:
System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception --> Interop.AndroidCrypto+SslExcetion: Exception of type 'Interop+AndroidCrypto+SslException was thrown -- End o inner exception stack trace at System.Net.Security.SslStream.
The code that makes the call is simple:
var httpClient = new HttpClient();
var responseFromServer = await httpClient.PostAsync(url, stringContent)
Any idea how to fix this? Maybe some backward compatibility settings on the server side? Something in android app?
Developer technologies | .NET | .NET MAUI
2 answers
Sort by: Most helpful
-
-
Murat 101 Reputation points
2023-08-10T17:45:46.5+00:00 Definitely use IHttpClientFactory to create HttpClient - the wrong way of initialization.
It caused so much trouble for me.
Nice example here for Net MAUI
https://github.com/yogigrantz/MAUIWithHttpClientFactory/tree/main/MAUIMultiPage
builder.Services.AddHttpClient();