Android开发中发送请求是报错:E/OkHttpTool: CLEARTEXT communication to 192.168.0.106 not permitted by network security policy

由于2018年发布的Android P限制了非加密的流量请求导致出现 not permitted by network security policy

解决办法如下:

 ①在res文件中添加xml的文件夹 在xml中在添加名称为:         network_security_config.xml 文件

Android开发中发送请求是报错:E/OkHttpTool: CLEARTEXT communication to 192.168.0.106 not permitted by network security policy_第1张图片

 

 

 ②在文件中设置cleartextTrafficPermitted为开启状态 true



    
    
    cleartextTrafficPermitted="true" />

 

 

 

在项目中找到  AndroidManifest.xml文件

Android开发中发送请求是报错:E/OkHttpTool: CLEARTEXT communication to 192.168.0.106 not permitted by network security policy_第2张图片

 

 

 ④在AndroidManifest.xml文件中添加配置  android:networkSecurityConfig="@xml/network_security_config" 如下:

android:networkSecurityConfig="@xml/network_security_config">

not permitted by network security policy 问题如下:

 

你可能感兴趣的:(Android开发中发送请求是报错:E/OkHttpTool: CLEARTEXT communication to 192.168.0.106 not permitted by network security policy)