Debug local APIs from emulator or connected device

Viewed 215

I know that this question is asked really a lot, but none of the answer is working for me.

I'm developing an Android Application on Android Studio, and trying to debug my .net core APIs.

I've tried:

  • The 10.0.2.2 IP Address
  • My local WI-FI IP Address
  • Emulator and Connected device are connected to the same WI-FI

So my question is how can I debug my local APIs from an emulator and from my connected device?

Is this still possible on latest updates?

1 Answers

I resolved it by ignoring ssl error during debugging. This can be done by using different instance of HttpClient as below.

#if DEBUG
        HttpClientHandler handler = new HttpClientHandler();
        handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
        {
            return true;
        };

        HttpClient httpClient = new HttpClient(handler);
#else
        HttpClient httpClient = new HttpClient();
#endif

Also you need to run your api using ip and port instead of localhost.

See "Bypass the certificate security check" section in below link. https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services#create-a-development-certificate

https://www.youtube.com/watch?v=HW_P3Eb-XWU

Related