question

NeidennX-8393 avatar image
0 Votes"
NeidennX-8393 asked RobCaplan edited

The SSL connection could not be established, see inner exception

Hi team, so im creating this app using Foursquare's Places API, everything seems good, but im not able to get the values from the API to the JSon variable, since when debbugin the app shows the attached error on the line before the Json (Line 23)

"The SSL connection could not be established, see inner exception"

Inner Exception says the following:

"Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/boringssl/ssl/handshake_client.c:1132"


I've tried using the next line of code on top of the method

  ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

I've also tried:

 client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;


But this last one is not recognizng the RemoteCertificateValidationCallback method, can some one please help ? Here's the code im using for the client


  ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
    
    
    
    
             List<Result> venues = new List<Result>();
    
             var url = VenueRoot.GenerateUrl(Latitude, Longitude);
    
                
             RestClient client = new RestClient(url);
              
               
    
             var request = new RestRequest(Method.Get.ToString());
    
         
    
             request.AddHeader("Accept", "application/json");
    
             request.AddHeader("Authorization", Constants.HEADER);
    
             RestResponse response = await client.ExecuteAsync(request);
    
             var json = response.Content.ToString();


dotnet-xamarinpartner-center-api
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, NeidennX-8393. Please make sure the server's certificate is valid. And try using HttpClient, and use AndroidClientHandler class to create the client.

Here is a similar issue thread, you could refer to it: https://github.com/xamarin/xamarin-android/issues/4688#issuecomment-658833938

0 Votes 0 ·

Hi @JarvanZhang-MSFT

Certificacte is valid, was updated Nov 2021, i changed the structure as suggested, but the issue persist the difference is that now th exception is not popping on the Response variable, im not quite sure how to solve this SSL conflict.

This is the current method


public static async Task<List<Result>> GetVenues(double Latitude, double Longitude)
{

         ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;




         List<Result> venues = new List<Result>();

         var url = VenueRoot.GenerateUrl(Latitude, Longitude);

       using (HttpClient Client = new HttpClient())
             {
                 try
                 {
                     var Response = await Client.GetAsync(url);
                     Client.DefaultRequestHeaders.Add("Accept", "application/json");
                     Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", Constants.HEADER);

                     var Json = await Response.Content.ReadAsStringAsync();
                     var venueRoot = JsonConvert.DeserializeObject<Venue>(Json);

                     venues = venueRoot.Results as List<Result>;

                 }
                 catch (Exception e)
                 {
                     var CatchException = e.ToString();

                 }


             }
           
         
         return venues;


0 Votes 0 ·

When creating the httpclient, please pass the AndroidClientHandler instance as the parameter. You could refer to this link: https://github.com/xamarin/xamarin-android/issues/4688#issuecomment-658833938

0 Votes 0 ·
Show more comments

0 Answers