Android 9 网络请求失败之CLEARTEXT communication to (域名) not permitted by network
错误记录:
原因是9之后安卓的安全策略提高,限制了明文流量的网络请求,9以下的版本都是没有问题的。
1.在res目录下新建xml文件夹
2.xml文件夹下新建名为 network-security-config.xml 的xml文件 (命名没固定要求)
3.内容如下
<?xml version="1.0" encoding="utf-8"?>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
4.然后在 AndroidManifest.xml 的application 标签中加上如下代码
android:networkSecurityConfig="@xml/network_security_config"
OK!
网友评论