Reputation: 63
I'm trying to access a development server API using nativescript-vue. I have added all the possible permissions in the android manifest, but it's giving the error: JS: Error: java.io.IOException: Cleartext HTTP traffic to url not permitted
Here is my manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:usesCleartextTraffic="true"
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:cleartextTrafficPermitted="true"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme">
Here is the network_security_config.xml file:
<?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">192.168.xxx.xxx</domain>
</domain-config>
</network-security-config>
And here is the Nativescipt-vue code:
httpModule.request({
url: "http://192.168.XXX.XXX:XXXX/func",
method: "POST",
headers: { "Content-Type": "application/json" },
content: data
}).then((response) => {
const result = response.content.toJSON();
}, (e) => {
console.error(e);
});
Upvotes: 2
Views: 1835
Reputation: 1562
Go in to App_Resources -> Android -> src\main -> AndroidManifest.xml add android:usesCleartextTraffic="true" go to the application xml section then do a tns update resources cmd.
Upvotes: 1
Reputation: 63
For those who face the same issue, tns platform remove android
and tns platform add android
worked for me. It started reading the updated manifest after this.
Upvotes: 3