flutter 报错 DioError [DioErrorType.DEFAULT]: Bad state: Insecure HTTP is not allowed by platform

错误解释

平台不支持不安全的 HTTP 协议,即不允许访问 HTTP 域名的地址。

产生原因

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

解决方案

在安卓/android/app/src/main/AndroidManifest.xml中,添加
android:networkSecurityConfig="@xml/network_security_config"

 

pic
flutter 报错 DioError [DioErrorType.DEFAULT]: Bad state: Insecure HTTP is not allowed by platform
 
 
 
 
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>

 

 

 
项目文件夹建一个子文件夹res/xml,把network_security_config.xml保存到res/xml下
 

 重新编译!

 

 

相关文章:

  • 2022-01-01
  • 2022-01-12
  • 2022-01-07
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-20
  • 2021-07-10
  • 2021-08-19
  • 2022-12-23
  • 2022-01-28
  • 2021-07-21
  • 2021-07-17
相关资源
相似解决方案