A call to SSPI failed SSL routines:OPENSSL s with Android 5.0 and lower versions

abdalrhmanabdalrhman Member ✭✭

I get this error in versions with Android 5.0 and lower versions

Error :
System.Net.WebException: Error: TrustFailure (A call to SSPI failed, see inner exception.) ---> System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> Mono.Btls.MonoBtlsException: Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED\n at /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/external/boringssl/ssl/handshake_client.c:1132\n at Mono.Btls.MonoBtlsContext.ProcessHandshake () [0x00038] in :0 \n at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncOperationStatus status) [0x0003e]

My Code:
`string result = "";
try
{
HttpClient client = await GetClient();
var MyUrl = Url + "api/Univesitemain/Yemeklistesi";

            result = await client.GetStringAsync(MyUrl);

        }
        catch (Exception ex)
        {
            var error = ex.ToString();
        }
        return JsonConvert.DeserializeObject<IEnumerable<YemekListesi>>(result);`

Best Answers

  • abdalrhmanabdalrhman ✭✭
    Accepted Answer

    My App it Worked after add this code To android MainActivity inside OnCreate()
    ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, errors) => true;

  • abdalrhmanabdalrhman ✭✭
    Accepted Answer

    Or add it like this

    public async Task GetClient()
    {
    HttpClientHandler handler = new HttpClientHandler();
    handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
    HttpClient client = new HttpClient(handler);
    client.DefaultRequestHeaders.Add("Accept", "application/json");
    return client;
    }

Answers

  • abdalrhmanabdalrhman Member ✭✭
    Accepted Answer

    My App it Worked after add this code To android MainActivity inside OnCreate()
    ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, errors) => true;

  • abdalrhmanabdalrhman Member ✭✭
    Accepted Answer

    Or add it like this

    public async Task GetClient()
    {
    HttpClientHandler handler = new HttpClientHandler();
    handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
    HttpClient client = new HttpClient(handler);
    client.DefaultRequestHeaders.Add("Accept", "application/json");
    return client;
    }

  • vinothswamivinothswami Member ✭✭✭
    edited October 11

    hello @abdalrhman ,

    which one is best and where should I assign client for the second solution you did return client.

  • abdalrhmanabdalrhman Member ✭✭

    @vinothswami said:
    hello @abdalrhman ,

    which one is best and where should I assign client for the second solution you did return client.

    ı am add thre second solution in my WebService class

  • vinothswamivinothswami Member ✭✭✭

    Thank you @abdalrhman, I did the first solution in Android main activity.

Sign In or Register to comment.