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_security_config.xml .
localhost for android version 6,7
YOUR_IP_ADDRESS for version 8,9
3 Likes
My Problem is same but i can’t solve this Link
have you solve the issue?
You must configurate config.xml with the next parameters:
…
…
…
Done the configutions mentioned here.But I am still facing the same issue.http calls failing in android 9 devices with response 0:URL null.
hi,
can you post your network config file and config.xml code here?
Thanks for your response
Please find the details below
added this in resources/android/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">ourdomain.com</domain>
<domain includeSubdomains="true">subdomain.ourdomain.com</domain>
</domain-config>
</network-security-config>
2) added in config.xml
<platform name="android">
allow-intent href="market:*" />
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:usesCleartextTraffic="true" />
<application android:networkSecurityConfig="@xml/network_security_config" />
</edit-config>
<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
3 Likes
changing the API url to https looks like the only working solution.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">abcd.com</domain>
</domain-config>
</network-security-config>
Try with this code use your domain in abcd.com , do not change the localhost
5 Likes
Thanks, this works for me!
1 Like
Shine
March 19, 2020, 6:56am
11
it works as charm for me. Thanks buddy
1 Like
TaGi
July 10, 2020, 1:33pm
13
Thanks sir, it was worked!
alexkhl
October 10, 2020, 9:51pm
14
Thank you! You saved my time!
I am working on ionic 5 using capacitor. I tried to call an Larvel api from localhost but am getting this error
First I got the below error
There was an error with the request: Cleartext HTTP traffic to localhost not permitted ionic
Fixed doing below in AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
Error changes
There was an error with the request: Failed to connect to localhost/127.0.0.1:80
I did not see any file in ionic 5 with the name:
network_security_config
Ionic Info:
Ionic CLI : 6.11.11 (C:\Users\Ahmad Raza Mughal\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic /angular 5.3.5
@angular-devkit /build-angular : 0.1000.8
@angular-devkit /schematics : 10.0.8
@angular /cli : 10.0.8
@ionic /angular-toolkit : 2.3.3
Capacitor:
Capacitor CLI : 2.4.2
@capacitor /core : 2.4.2
Utility:
cordova-res : 0.14.0
native-run : 1.0.0
System:
NodeJS : v12.16.2 (C:\Program Files\nodejs\node.exe)
npm : 6.14.4
OS : Windows 10
Please help with the above?
Thanks
@ahmadrazainbox
check the network_config file in your folder path\resources\android\xml and change as the solution given.
I created this file manually in AndroidStudio and it’s works for me!
Try to create res/xml/network_security_config.xml with text described above, and put link to it in “application” section in AndroidManifest.xml (like this: application android:networkSecurityConfig="@xml /network_security_config")
Thanks @prabhashi1 , it worked smoothly
Damnnn, Thanks to this, finally work