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

 

 

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

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <!--开发中可以考虑使用-->
    <!--Android API 28 关闭HTTPS服务器监测-->
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

 

 

 

在项目中找到  AndroidManifest.xml文件

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

 

 

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

<application
        android:networkSecurityConfig="@xml/network_security_config">
</application>

not permitted by network security policy 问题如下:

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

 

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

上一篇:android入门学习资源


下一篇:解决React中打开App或者下载App问题