java.io.IOException: Cleartext HTTP traffic to e.hiphotos.baidu.com not permitted

java.io.IOException: Cleartext HTTP traffic to e.hiphotos.baidu.com not permitted

Android P(Android 9) 系统的安卓设备无论是接收或者发送数据,都不能明码传输,需要使用(Transport Layer Security)传输层安全协议Https,Android P(Android 9)开始原生不支持http协议需要适配

解决方法:

1、APP改用https请求
2、targetSdkVersion 降到27以下

3、res目录下创建xml目录 ,xml目录里面新建xml文件 名字叫 network_security_config.xml
文件内容如下

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>
修改清单文件 application头标签加入属性
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:networkSecurityConfig="@xml/network_config"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

</application>
 
 
 

猜你喜欢

转载自www.cnblogs.com/zhou2016/p/13200026.html