java.net.UnknownServiceException: CLEARTEXT communication to 192.168.20.142 not permitted by network

项目运行出现异常:

java.net.UnknownServiceException: CLEARTEXT communication to 192.168.20.142 not permitted by network

出现原因:因为 Android P 是默认禁止访问http的API的 所以想要跳过https的限制要这样做

处理方案:在res文件夹下创建xml目录,新建network_https_config.xml文件

java.net.UnknownServiceException: CLEARTEXT communication to 192.168.20.142 not permitted by network

内容如下:

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

然后在AndroidManifest.xml的application节点添加如下内容:

android:networkSecurityConfig="@xml/network_security_config"

java.net.UnknownServiceException: CLEARTEXT communication to 192.168.20.142 not permitted by network

 然后重新编译运行就可以啦

上一篇:阿里云云服务器ECS介绍


下一篇:猪齿鱼的微服务之路(四):深入理解微服务配置中心