Android - Use retrofit2 to request dynamic IP address

416 Views Asked by At

Using Retrofit2 to perform network requests, and now trying to call a service which is in a configurable IP dress, but I get CLEARTEXT communication to **IP_ADDRESS*** not permitted by network security policy.

I have read in forums that we can add the IP address to network_security_config.xml, but I need address to be dynamically. Also tried to add in manifest the flag usesCleartextTraffic but same error raises (tested on Android 10)

How can I request a dynamic IP address without having to specify it in network_security_config.xml?

1

There are 1 best solutions below

0
aref behboodi On BEST ANSWER

use below xml code for network_security_config.xml

<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

its should work! im sorry for my weak english