zoukankan      html  css  js  c++  java
  • 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"
    
    

    在这里插入图片描述

    在这里插入图片描述

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

    androidappsrcmain esxml etwork_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>
    

    在这里插入图片描述

    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>
    

    在这里插入图片描述

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

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

    备注:网上还查资料看到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>
    
  • 相关阅读:
    STL
    STL
    Python编程-基础知识-条件判断
    STL
    springmvc 自定义注解
    Springboot 入口类及其实现自动配置的原理
    Java RestTemplate post请求传递参数遇到的坑
    Spring中@Autowire的底层原理解析(附详细源码阅读步骤)
    非常详细的SpringBoot-自动装配原理
    为何一个@LoadBalanced注解就能让RestTemplate拥有负载均衡的能力?
  • 原文地址:https://www.cnblogs.com/sugartang/p/15302953.html
Copyright © 2011-2022 走看看