美文网首页
Android9.0默认网络请求使用https解决方案

Android9.0默认网络请求使用https解决方案

作者: 玖玖君 | 来源:发表于2019-07-11 18:30 被阅读0次

测试手机提示更新至安卓9.0,原以为差别不大,就更新了,结果导致app获取不到后台数据。

解决方案:
经查阅资料,原来是Android9.0加入了所有的网络请求默认使用https,然而我的是http,最终加入相应的配置才能完成http的请求。
在AndroidManifest.xml加入以下代码得以解决。

android:networkSecurityConfig="@xml/network_security_config"

在res/xml新建network_security_config.xml,xml内容如下:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
     <base-config cleartextTrafficPermitted="true" />
</network-security-config>

此作品归本作者所有,任何形式的转载都请联系作者获得授权并注明出处。

相关文章

网友评论

      本文标题:Android9.0默认网络请求使用https解决方案

      本文链接:https://www.haomeiwen.com/subject/axqjkctx.html