Rag*_*wal 28 android http flutter
Flutter 团队最近进行了此更改,现在不允许不安全的 http 连接。 https://flutter.dev/docs/release/break-changes/network-policy-ios-android
我想知道如何将我的手机上的 Flutter 应用程序连接到我的 PC 上运行的本地 Go 服务器。
我的服务器正在运行:http : //192.168.29.45 : 4001但它没有连接到它。
Sur*_*gch 52
Generally it is required (and preferable) to use https links rather than http links. However, this can be overridden as shown below.
Open the AndroidManifest.xml file in the android/app/src/main folder. Then set usesCleartextTraffic
to true
.
<application
...
android:usesCleartextTraffic="true"
... >
Run Code Online (Sandbox Code Playgroud)
See this question for more.
Open the Info.plist file in the ios/Runner folder. Then add the following key.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
See this answer for more.
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>
Run Code Online (Sandbox Code Playgroud)
正如我已经回答的那样。临时解决您的问题。首先network_security_config
在 res/xml 目录中命名的文件中添加以下配置(我的完整路径是/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>
Run Code Online (Sandbox Code Playgroud)
然后在您的 AndroidManifest.xml 文件中的<application
标签内,添加以下配置:
android:networkSecurityConfig="@xml/network_security_config"
Run Code Online (Sandbox Code Playgroud)
这可能允许 http 流量。但它只是用于在本地环境或测试环境中进行调试,最好的方法是使用 https 流量。更多信息:如何在 Android (9) Pie 中允许所有网络连接类型 HTTP 和 HTTPS?
实现这一点的简单方法是在您的 AndroidManifest.xml 中使用此属性,这将允许 http 流量:
<application android:usesCleartextTraffic="true">
</application>
Run Code Online (Sandbox Code Playgroud)
对我来说最简单的解决方案是将以下行添加到我的调试清单文件中,该文件可以在 $project_path\android\app\src\debug\AndroidManifest.xml 中找到:
<application android:usesCleartextTraffic="true"/>
重要信息- 直到我重新启动模拟器后它才起作用,因此请确保不要跳过此步骤。
最简单的方法:
安卓
转到 android/app/src/main/AndroidManifest.xml。打开 AndroidManifest.xml 文件。然后在里面设置 android:usesCleartextTraffic="true"
例子:
<uses-permission android:name="android.permission.INTERNET" /> //This line add
<application
android:name="io.demo.app.test"
android:label="ProjectName"
android:usesCleartextTraffic="true" //This line add
android:icon="@mipmap/ic_launcher">
Run Code Online (Sandbox Code Playgroud)
iOS系统
转到主词典下的 ios/Runner/info.plist 并打开 info.plist 设置以下代码行:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
完成此陡峭后,关闭此应用程序并运行:
小智 5
在 android/app/AndroidManifest
<application ...
android:networkSecurityConfig="@xml/network_security_config" >
<meta-data android:name="io.flutter.network-policy"
android:resource="@xml/network_security_config"/>
Run Code Online (Sandbox Code Playgroud)
然后创建一个文件夹xml里面创建一个文件:network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
29259 次 |
最近记录: |