title: Accept self-signed certificates in Xamarin Android
body: <p>I got a <em>Xamarin Forms</em> project and inside the MainPage.xaml.cs file i want to perform a request to my server. The server is written in <em>ASP.NET Core</em> 2 and is running with a self-signed certificate.</p>
  
  <p>To buy a certificate isn't a solution for my problem, because customers don't want it and application only running in LAN.</p>
  
  <p>In my MainPage.xaml.cs file the Http-request looks like this:</p>
  
  <pre><code>HttpClient m_Client = new HttpClient();
  var uri = new Uri(myURL);
  
  var response = await m_Client.GetAsync(uri);
  
  if (response.IsSuccessStatusCode)
  {
      ...
  }
  </code></pre>
  
  <p>So far so good. If I bring the app on <strong>Android</strong> and try to perform the request, Android throws a SSL Exception for not finding a CA for my certificate. </p>
  
  <p>How can I communicate with my server using a self-signed certificate?</p>
  
  <p>I looked up the problem and find a lot of solutions like:</p>
  
  <pre><code>ServicePointManager
          .ServerCertificateValidationCallback +=
          (sender, cert, chain, sslPolicyErrors) =&gt; true;
  </code></pre>
  
  <p>If you add this code to your MainActivity.cs file in your Android project, it should accept all certificates. But that is not working for me. It seems like this method never gets called.</p>
  
  <p>Any suggestions how to make the communication happen?</p>
  
  <p>Regards</p>