Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore SSL certificate errors in Xamarin.Forms (PCL)

Is there any way to do something like described here: https://stackoverflow.com/a/2675183 but in Xamarin.Forms PCL App? I'm using HttpClient to connect to the server.

like image 269
anaid Avatar asked Feb 20 '15 13:02

anaid


1 Answers

ServicePointManager isn't defined in PCL but defined in platform specific classes.

There are ServicePointManager in both Xamarin.iOS and Xamarin.Android with same usage. You can reference it inside any classes in your platform projects. However, currently there is no such class and seems no way to do so for Windows Phone app.

Example:

// Xamarin.Android  public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity {     protected override void OnCreate(Bundle bundle)     {         // You may use ServicePointManager here         ServicePointManager             .ServerCertificateValidationCallback +=             (sender, cert, chain, sslPolicyErrors) => true;          base.OnCreate(bundle);          global::Xamarin.Forms.Forms.Init(this, bundle);         LoadApplication(new App());     } }  // Xamarin.iOS  public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate {     public override bool FinishedLaunching(UIApplication app, NSDictionary options)     {         ServicePointManager             .ServerCertificateValidationCallback +=             (sender, cert, chain, sslPolicyErrors) => true;          global::Xamarin.Forms.Forms.Init();         LoadApplication(new App());          return base.FinishedLaunching(app, options);     } } 
like image 78
Alex Lau Avatar answered Sep 24 '22 23:09

Alex Lau