美文网首页Android开发经验谈Android技术知识Android开发
Android9.0默认网络请求使用https解决方案

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

作者: i小灰 | 来源:发表于2020-09-07 02:13 被阅读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/icufektx.html