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
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
Finally got a solution from this
ionic 4 app sends http request for android version 6,7 but gives an error saying CLEARTEXT http traffic (not permitted). I have trying to solve this by adding android:usesCleartextTraffic="true"
but ionic default is true for usesCleartextTraffic.
and also i tried to change url http to https. but nothing works for me.
so i solved this issue temporarily by adding
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">YOUR-IP_ADDRESS</domain>
to my network_secu…
Have to add android:usesCleartextTraffic="true"
on android/app/src/main/AndroidManifest.xml
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,