美文网首页
Android9.0 http网络请求解决方案

Android9.0 http网络请求解决方案

作者: 有腹肌的豌豆Z | 来源:发表于2019-06-13 16:05 被阅读0次

Android9.0 http网络请求解决方案

由于 Android P 限制了明文流量的网络请求,非加密的流量请求都会被系统禁止掉。

如果当前应用的请求是 htttp 请求,而非 https ,这样就会导系统禁止当前应用进行该请求,如果 WebView 的 url 用 http 协议,同样会出现加载失败,https 不受影响。

解决方法:

1. 在 res 下新建一个 xml 目录,然后创建一个名为:network_security_config.xml 文件 ,该文件内容如下:

<?xml version="1.0" encoding="utf-8"?>

<network-security-config>

<base-configcleartextTrafficPermitted="true"/>

</network-security-config>

2. 然后在 AndroidManifest.xml application 标签内应用上面的xml配置:

        android:name=".App"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:networkSecurityConfig="@xml/network_security_config"

        android:roundIcon="@mipmap/ic_launcher_round"

        android:theme="@style/AppTheme"></application>


targetSdkVersion 降级回到 27 --> 怎么可能呢

Thank you for sharing your talent as a free resource online.

相关文章

网友评论

      本文标题:Android9.0 http网络请求解决方案

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