安卓 : Allow Cleartext http

标签 android http android-9.0-pie cleartext

我有一个特定的要求,其中我必须阻止来自应用程序的所有 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/

相关文章:

python - python将使用哪些端口发送html请求?使用 urllib 或 urllib2

android - 如何使用 AccessibilityService 在 Android Oreo 及更高版本的 UI 窗口中单击?

android - 使用 Android Pie 时下载失败并出现错误 400

android - 无法使用2种以上的布局

android - 将视频从资源加载到 HTML5 webview - Android

java - Android: Volley HTTP 补丁请求

android - 是否有 API 可以检测操作系统正在使用哪个主题 - 深色或浅色(或其他)?

android - Adobe AIR CameraRoll 无法在 Android 6.0 上选择照片

android - 使用位图转换 JSON 对象

php - 使用 PHP 从 MySQL 检索图像