我有一个特定的要求,其中我必须阻止来自应用程序的所有 http 请求,但是库使用了一个特定的 http url,我必须将其列入白名单。 尝试按如下方式设置 network_security_config xml,但无法加载该 http url。还在 list 文件中定义了 network_security_config xml。
网址格式为 http://abc.xyz.org
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="false" />
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">"abc.xyz.org"</domain>
</domain-config>
</network-security-config>
我在这里缺少什么吗?
最佳答案
使用以下域规则创建 xml/network_security_config
文件。
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<!-- As you want to pass domain-specific traffic -->
<domain-config cleartextTrafficPermitted="true">
<!-- Add your specific domain you want to pass without https -->
<domain includeSubdomains="true">abc.xyz.org</domain>
</domain-config>
</network-security-config>
在 list 中添加网络安全配置:
<application android:label="your App Name" android:icon="@drawable/icon" android:networkSecurityConfig="@xml/network_security_config">
关于安卓 : Allow Cleartext http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58432172/