Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

HTTPS ignore certificate

Hello, I want to use REST service as https://developer.xamarin.com/samples/xamarin-forms/WebServices/TodoREST/

But with HTTPS security and untrusted certificate (my own server). Most of Microsoft.Net.Http.HttpClient support this feature. But HttpClient for PLC (portable library) does not. Is here some solution to this problem?

Answers

  • kentuckerkentucker USMember ✭✭✭✭✭
  • MommMomm USMember ✭✭✭
    edited June 2016

    @TomKello, add this line to onCreate (MainActivity) and FinishedLaunching (AppDelegate).

    System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

    I used this approach when accessing a Dev server.

    Please let me know if it helps you out.

  • TomKelloTomKello USMember

    Yes, that should work. But it works only in Android and the same you can use for iOS, but not in UWP.

  • PaoloManciniPaoloMancini ITMember
    edited June 2016

    Hi, I use HttpClient for PLC (portable library). I have a Rest API with Https. I use System.Net.ServicePointManager.ServerCertificateValidationCallback to accept self signed certificate.

    It works but the first time I execute the call It takes 15 seconds. After it takes 2 seconds.
    It seems the call takes long time only the first time, or after a long time that I don't use the app. How can I achieve this??!

    I've test also with ModernHttpClient but the time is the same.

  • curtis.ehrhartcurtis.ehrhart USMember ✭✭

    trying to add this to the main project

    System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

    but ServicePointManager is not in System.Net

    When I try to add a reference to System.Net.ServicePoint, i get this error

    All of the Framework assemblies are already referenced. Please use the Object Browser to explore the referenced Framework

    I'm not sure how to add the reference now

  • AhmedElashkerAhmedElashker USMember ✭✭

    @Momm said:
    @TomKello, add this line to onCreate (MainActivity) and FinishedLaunching (AppDelegate).

    System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

    I used this approach when accessing a Dev server.

    Please let me know if it helps you out.

    It's working for iOS

    For Android I'm still getting this error however "java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."

  • Suriya_KalidossSuriya_Kalidoss Member ✭✭✭

    Any Updates regarding this ?????

  • Suriya_KalidossSuriya_Kalidoss Member ✭✭✭

    Im also facing this error

  • boletus151boletus151 USMember ✭✭
    edited January 26

    Any update?
    I still cannot connect on Android, :sweat:

    iOS is working fine with this:
    System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

Sign In or Register to comment.