解决Android9.0 http连接无法访问,CLEARTEXT communication not permitted by network security policy

解决Android9.0 http连接无法访问,CLEARTEXT communication not permitted by network security policy_第1张图片
app

Android P 禁止了http连接?(WTF!数据请求失败,图片也加载不出来)
LogCat错误日志显示:
... CLEARTEXT communication not permitted by network security policy ...

解决方法

最简单的解决方法就是明确指定接受某些主机的明文。

  • 添加安全配置文件


    
        ...
    

  • main -> res -> xml 新建network_security_config.xml
  1. 允许指定http链接


    
        example1.com
        example2.com
    

  1. 允许所有http链接


    
        
            
            
        
    

就这样!

参考文档:
Android P - CLEARTEXT communication not permitted by network security policy
网络安全性配置 | Google Developers

你可能感兴趣的:(解决Android9.0 http连接无法访问,CLEARTEXT communication not permitted by network security policy)