Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Insecure http is not allowed by platform

Flutter team recently made this change and now insecure http connections are not allowed. https://flutter.dev/docs/release/breaking-changes/network-policy-ios-android

I would like to know how can I connect my flutter app on mobile to local go server running on my PC.

My server is running on: http://192.168.29.45:4001 but it is not connecting to it.

like image 804
Raghav Aggiwal Avatar asked Oct 02 '20 13:10

Raghav Aggiwal


People also ask

How do I allow HTTP request in flutter?

Open the AndroidManifest. xml file in the android/app/src/main folder. Then set usesCleartextTraffic to true .


3 Answers

Generally it is required (and preferable) to use https links rather than http links. However, this can be overridden as shown below.

Android

Open the AndroidManifest.xml file in the android/app/src/main folder. Then set usesCleartextTraffic to true.

<application
    ...
    android:usesCleartextTraffic="true"
    ...   >

See this question for more.

iOS

Open the Info.plist file in the ios/Runner folder. Then add the following key.

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

See this answer for more.

macOS

This is the same as iOS. Open the Info.plist file in the macos/Runner folder. Then add the following key.

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>
like image 142
Suragch Avatar answered Oct 23 '22 19:10

Suragch


As I have already answered. To temp fix your problem. First add the following config in the file named network_security_config inside res/xml directory(my full path is /Users/dolphin/source/third-party/Cruise/android/app/src/main/res/xml/network_security_config):

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

then in your AndroidManifest.xml file, inside <application tag, add the following config:

android:networkSecurityConfig="@xml/network_security_config"

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

like image 40
Dolphin Avatar answered Oct 23 '22 18:10

Dolphin


The easy way to implement this is to use this attribute inside your AndroidManifest.xml this will allow http traffic:

<application android:usesCleartextTraffic="true">
</application>

More info here

like image 8
Mateen Kiani Avatar answered Oct 23 '22 18:10

Mateen Kiani