问题如图:
communication to ****not permitted by network security policy 网络安全不允许与进行明文通信
原因: Android P(版本27以上) 限制了明文流量的网络请求,非加密的流量请求都会被系统禁止掉。
如果当前应用的请求是 htttp 请求,而非 https ,这样就会导系统禁止当前应用进行该请求。
解决方式:
推荐的做法是服务器和本地应用都改用 https ,测试时为了方便使用http,上线时应该都会用https才比较安全。
解决办法:1.在 res 下新建一个 xml 目录,然后创建一个名为:network_security_config.xml 文件 ,该文件内容如下:
<?xml version="1.0" encoding="utf-8"?> 在清单文件中配置: <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_names"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".base.MIApp"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
或者服务器和本地应用都改用 https