0

I need to get a JSON response from an IP address (No Domain Name connected), but flutter 2.0 doesn't allow HTTP, so I followed this answer to enable it, but the problem I face is I dont have domain name, to replace here:

<?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>

I tried replacing with IP but it throws error that IP is not recognised as domain name.

<domain includeSubdomains="true">x.x.x.x</domain> #doesn't work

Any solution to allow HTTP traffic from IP address.

PS: I know its unsafe.

EDIT:

I tried this methods:

  1. Setting res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

Doesn't work.

  1. Setting res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">65.0.XX.136</domain>
    </domain-config>
</network-security-config>

Doesn't Work.

  1. Setting android:usesCleartextTraffic="true" in application tag of AndroidManifest.xml.

Doesn't work.

thisisjaymehta
  • 614
  • 1
  • 12
  • 26
  • Can you provide your code and IP address? I've worked with some similar to your case and no problems. – Ουιλιαμ Αρκευα Mar 06 '21 at 16:42
  • Try without the network security config file. – blackapps Mar 06 '21 at 17:06
  • @blackapps Without network config file it was not working, thats why I had to search google and came to know that flutter 2 doesn't allow cleartext connections by default. – thisisjaymehta Mar 07 '21 at 03:41
  • @ΟυιλιαμΑρκευα I edited my question with code I used, I can show you real IP in chat or something, but I dont know how to start a chat. – thisisjaymehta Mar 07 '21 at 03:50
  • `that flutter 2 doesn't allow cleartext connections by default. ` Think that flutter does not mind. Its the Android OS on your device that minds. And so your app has to request using clear text traffic. – blackapps Mar 07 '21 at 09:41
  • Strange. For a lot of apps i use android:usesCleartextTraffic="true" and that is always enough. Never needed that file. Well..no Flutter. – blackapps Mar 07 '21 at 09:43
  • @blackapps Before upgrading to flutter 2, all my apps were running fine on cleartext traffic on my Android 10 phone. After upgrading to flutter 2.0.0 two days ago, this issue is coming. – thisisjaymehta Mar 07 '21 at 10:15
  • I wonder why Flutter minds. – blackapps Mar 07 '21 at 11:14

0 Answers0