androidhttpcleartext

Cleartext HTTP traffic to ... not permitted


my program takes an URL from the user, so it may make request to any website of the internet. I'm trying to make this possible, I looked up all the answers about "Android HTTP Cleartext" errors, and made this, but it still doesn't let me connect my test local PHP server, what am I missing here?

<uses-permission android:name="android.permission.INTERNET" />
...
<application
...
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
tools:ignore="UnusedAttribute"

My security config:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">api.example.com</domain>
    </domain-config>
</network-security-config>

Thanks!


Solution

  • Try changing your network_security_config.xml as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
        <base-config cleartextTrafficPermitted="true"></base-config>
    </network-security-config>