Bad state: Insecure HTTP is not allowed by platform:

node.jsFlutterHttpMobileConnection

node.js Problem Overview


I'm having the following problem: E/flutter ( 7144): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Bad state: Insecure HTTP is not allowed by platform: http://myIPv4:PORT/PATH.

This is my flutter code to requisition

And this is the backend that I can access: My backend code

I already allowing the access by cors, but not even this help me. I already tried to use the http://localhost:port/path and http://myIP:port/path but doesn't worked!

But if I try access directly by browser so work.

Browser Print

node.js Solutions


Solution 1 - node.js

For Android:

This behavior may be omitted following migration guide: https://flutter.dev/docs/release/breaking-changes/network-policy-ios-android.

or... Just add in android/app/src/main/AndroidManifest.xml:

android:usesCleartextTraffic="true" to <application /> also dont forget to take INTERNET PERMISSION:

<uses-permission android:name="android.permission.INTERNET" /> <!-- This Line -->

<application
        android:name="io.flutter.app.FlutterApplication"
        android:label="receipt"
        android:usesCleartextTraffic="true" <!-- This Line -->
        android:icon="@mipmap/ic_launcher">

For iOS:

Allow insecure/HTTP requests globally across your application on iOS, you can add this to your ios/Runner/info.plist under the main dictionary definition:

<key>NSAppTransportSecurity</key>
<dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
</dict>

Be warned that you will need to have an explanation for Apple's review team when enabling this, otherwise your app will get rejected on submission.

Thank you.

Solution 2 - node.js

  1. Navigate to your project.
  2. Go to yourapp\android\app\src\debug\AndroidManifest.xml.
  3. Add this line.
<application android:usesCleartextTraffic="true">
</application>

For further details, follow this link.

Solution 3 - node.js

This problem is solved here.

https://flutter.dev/docs/release/breaking-changes/network-policy-ios-android

You just need to change the HTTP to HTTPS. Like this

Response response = await get('https://worldtimeapi.org/api/timezone/Africa/Nairobi';);

Solution 4 - node.js

I solved it by following this step:

  1. android/app/src/main/AndroidManifest.xml then write

    <application
    android:usesCleartextTraffic="true"
    android:label="laundry"
    android:icon="@mipmap/ic_launcher">
    <uses-library
     android:name="org.apache.http.legacy"
     android:required="false" />  </application>
    

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLucas Guimar&#227;es SantosView Question on Stackoverflow
Solution 1 - node.jsPratik ButaniView Answer on Stackoverflow
Solution 2 - node.jsMridul BaglaView Answer on Stackoverflow
Solution 3 - node.jsjjuma1992View Answer on Stackoverflow
Solution 4 - node.jsM.Adnan IjazView Answer on Stackoverflow