Ionic 5 Http failure response for (unknown url): 0 Unknown Error in ionic capacitor. when calling api on simulator

I have an ionic 5 capacitor application that calls a .NET Core backend API. It works correctly on chrome browser and android device , (emulator and real device) after build.

When I run using this command ionic cap run ios -l --external it’s working fine REST API on IOS simulator.

But If I run this command ionic cap build ios after that run simulator then REST API not working.

Have searched many solutions on google and applied in the application code but have not found any solution. Please help me how can I do this?

Thanks

Probably 90% of the “error code 0” posts I see here are caused by one of two things:

  • trying to use insecure http endpoints instead of https ones
  • insufficient CORS setup on server
1 Like

Let’s say you’ve got a server running on your machine at http://localhost:3000 . This is fine when you are testing your Ionic application on your computer because you can just send your HTTP requests to:

http://localhost:3000/photos/upload

But once you deploy the application as a native iOS or Android application to your device, this URL will no longer work since the context for localhost means that it will no longer be referring to the computer where your server is running. So, how do we forward these requests from our mobile device to the computer that is running the server/backend?

https://eliteionic.com/tutorials/accessing-localhost-from-mobile-device-ios-android/