0

I'm trying to pass my full Rest service from http to https.

I created a self-signed certificate, I had it to IIS Express. I validate it on google Chrome and it work perfectly fine with postman. My rest service work in http and https.

I use a PCL project (IOS and Android) everything is working fine with http request but I have exception with https request. the exception message is null.

I tried to create a test certificate directly from Visual Studio 2015 but the button is disabled in properties ->Signing.

I also tried to install my self-signed certificate as a Trusted Root but no success for the communication between my simulator and my rest Service.

my code

public partial class MainPage : ContentPage
{
    private string url = string.Empty;
    private HttpClient _client;


    public MainPage()
    {
        InitializeComponent();
        switch (Device.RuntimePlatform)
        {
            case Device.iOS:
                _client = new HttpClient(new NSUrlSessionHandler());
                break;
            case Device.Android:
                _client = new HttpClient();
                break;
        }
        _client = new HttpClient();
        test();


    }

    private async void test()
    {
        //url = "http://192.168.1.106:9630/PrototypeB.svc/Test";
        url = "https://192.168.1.106:44301/PrototypeB.svc/Test";
        try
        {
            var _content = await _client.GetStringAsync(url);
            List<Test> _posts = JsonConvert.DeserializeObject<List<Test>>(_content);
        }
        catch (HttpRequestException e)
        {
            string test = e.Message;
        }
        catch (Exception e)
        {
            string test = e.Message;
        }
    }
}

How can I communicate with my Android and IOS Simulator with https and self-signed certificate?

Kevin Li
  • 2,258
  • 1
  • 9
  • 18
Ludovic
  • 25
  • 1
  • 11

1 Answers1

-2

You can use ServicePointManager to ignore the certificate validation check.

Execute the code in your iOS and Android platforms like this:

System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => { 
                         return true; 
                     };

References:

Also, ModernHttpClient Pro provide this feature, but it is not free.

Kevin Li
  • 2,258
  • 1
  • 9
  • 18