CORS on device (build version)

Im having problem on the API request,
Im having Cross Origin Error
Build it using ionic cap build android --targe=<device id>
Already tried

  • adding proxy on ionic.config.json and changes the baseURL to api/v1 but it return 200 status but it does not connect to the api only blank white page
  • Added headers to the php also but still no luck
  • Added headers to axios also
    image
    image

PHP

This is the API Call when I did not add baseUrl to axios baseURL but it displays empty and Im guessing it does not connect to the API


I don’t think it makes much sense to invest time in troubleshooting CORS in this environment. Before doing anything else, I would organize things so that your backend is hosted somewhere with (a) proper forward and reverse DNS, and (b) a valid SSL certificate. Additionally, every endpoint in your Ionic code should use a hostname (no IP addresses, no localhost) and begin with https.

When you deploy the app, those things are going to need to be true anyway.

1 Like

thanks for the hint mate :slight_smile:

Finally got a solution from this

Have to add android:usesCleartextTraffic="true" on android/app/src/main/AndroidManifest.xml

image

Also create android/app/src/main/res/xml/network_security_config.xml and added

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true"><api IP Address></domain>
    </domain-config>
</network-security-config>

But dont know which one works,