1

I'm trying to execute an http request to a local server that I did, but I'm getting the following I / flutter (28338) error message: Bad state: Insecure HTTP is not allowed by the platform: http: // mylocalip / auth / login, does anyone know how to solve?

Note: I am also using the modular flutter and mobx

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 1.22.0-10.0.pre.251, on Microsoft
    Windows [versão 10.0.19041.508], locale pt-BR)

[√] Android toolchain - develop for Android devices (Android
    SDK version 30.0.2)
[√] Android Studio (version 4.0)
[√] Connected device (1 available)

• No issues found!
I'm trying to make a request to a local http server, the request is a post for a login system that receives username and password by parameter

login() async {
try {
  var response = await http.post(http://mylocalip/auth/login,
      body: {'username': 'maximosdrr', 'password': '621251'});
  print(response.statusCode);
} catch (e) {
  print(e);
}
}

And the output on the console is as follows: I / flutter (28338): Bad state: Insecure HTTP is not allowed by platform: http://mylocalip/auth/login

Hiran Júnior
  • 345
  • 2
  • 9
  • 1
    Take a look on doc https://flutter.dev/docs/release/breaking-changes/network-policy-ios-android – Kate Sep 19 '20 at 16:55

1 Answers1

1

To temp fix your problem. First add a config in res/xml(my full path is /Users/dolphin/source/third-party/Cruise/android/app/src/main/res/xml) folder:

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

then in your AndroidManifest.xml file add this config:

android:networkSecurityConfig="@xml/network_security_config"

this could allow http traffic. But it just using to debug, the best way is to using https traffic. more info: How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

Dolphin
  • 29,069
  • 61
  • 260
  • 539