平台不允许 Flutter Insecure http [英] Flutter Insecure http is not allowed by platform

查看:47
本文介绍了平台不允许 Flutter Insecure http的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Flutter 团队最近进行了此更改,现在不允许不安全的 http 连接.https://flutter.dev/docs/release/break-changes/network-policy-ios-android

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

我想知道如何将我在移动设备上的 Flutter 应用程序连接到我的 PC 上运行的本地 Go 服务器.

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

我的服务器正在运行:http://192.168.29.45:4001 但它没有连接到它.

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

推荐答案

通常需要(并且最好)使用 https 链接而不是 http 链接.但是,这可以被覆盖,如下所示.

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

打开 android/app/src/main 文件夹中的 AndroidManifest.xml 文件.然后将 usesCleartextTraffic 设置为 true.

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

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

参见这个问题 了解更多.

打开 ios/Runner 文件夹中的 Info.plist 文件.然后添加以下键.

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.

这与iOS相同.打开 ma​​cos/Runner 文件夹中的 Info.plist 文件.然后添加以下键.

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>

这篇关于平台不允许 Flutter Insecure http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆