flutter 2.X报错 Bad state: Insecure HTTP is not allowed by platform:

发布时间:2022-07-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了flutter 2.X报错 Bad state: Insecure HTTP is not allowed by platform:脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

flutter2.x开发遇到的问题 Bad state: Insecure HTTP is not Allowed by platform:

翻译过来就是:错误状态:平台不允许不安全的HTTP:

产生原因:IOS 和 AndROId 9.0 对网络请求做了一些限制,不能直接访问 Http 域名的地址。

解决方案如下:

Android 配置

找到下图位置,添加这两行代码

      android:usesCleartextTraffic="true"
      android:networkSecurITyconfig="@XMl/network_security_config"

flutter 2.X报错 Bad state: Insecure HTTP is not allowed by platform:

flutter 2.X报错 Bad state: Insecure HTTP is not allowed by platform:

添加 network_security_config.xML 文件,没有这个文件就创建一个,注意一下路径哦

androidappsrcmainresxmlnetwork_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>

flutter 2.X报错 Bad state: Insecure HTTP is not allowed by platform:

IOS 配置

找到 ios/Runner/Info.plist,添加关于 NSAppTransportSecurity NSAllowsArbitraryLoads 的配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PubLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.COM/DTDs/PRopertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSAppTransportSecurity</key> 
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>
</dict>
</plist>

flutter 2.X报错 Bad state: Insecure HTTP is not allowed by platform:

搞完以后,重启项目!!重启重启重启重启!重启解决一切问题!!!!

下面的可能用不到,一般上面的都可以解决问题了哦~~~

备注:网上还查资料看到network_security_config.xml有其他配置办法

此办法参考链接:https://www.cnblogs.com/sea-stream/p/13908198.html

补充如下

network_security_config.xml

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

or

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>

<!-- 配置7.0抓包--start -->
<debug-overrides>
    <trust-anchors>
        <!-- Trust user added CAs while debuggable only -->
        <certificates src="user"/>
    </trust-anchors>
</debug-overrides>
<!-- 配置7.0抓包--end -->

<!-- 配置9.0明文请求--start -->
<base-config cleartextTrafficPermitted="true" />
 <!-- 配置9.0明文请求--end -->   

</network-security-config>

脚本宝典总结

以上是脚本宝典为你收集整理的flutter 2.X报错 Bad state: Insecure HTTP is not allowed by platform:全部内容,希望文章能够帮你解决flutter 2.X报错 Bad state: Insecure HTTP is not allowed by platform:所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。