Error Hostname not verified when sending request on Android

Igor Kravchenko 281 Reputation points
2022-06-12T14:05:57.973+00:00

Hi!
I cannot send request to our web server. We use self-signed certificate. Exception throws on

using HttpResponseMessage response = await HttpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, cancellationToken);  

I get Javax.Net.Ssl.SSLPeerUnverifiedException

Hostname *** not verified:  
    certificate: ***  
    subjectAltNames: ***  

StackTrace (removed my calls because nothing interesting there):

   at Xamarin.Android.Net.AndroidMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs:line 389  
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)  

In our Xamarin Forms project the same code works fine.
Is it a bug? How can I resolve this?
Thanks.

Developer technologies .NET .NET MAUI
{count} votes

2 answers

Sort by: Most helpful
  1. Sikandar Amla 1 Reputation point
    2022-10-21T20:24:25.947+00:00

    I have exact same issue. Self-signed certificate and trying to connect to a remote server (no localhost). @Igor Kravchenko Could you find any solution to this error?

    Thanks


  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-10-21T20:49:07.887+00:00

    you can not override the ssl checking. you must install and trust the self cert in the android device.

    google for instruction to instal a self signed cert for your device


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.