network_security_config.xml 中的多个子域如何

Multiple subdomains in network_security_config.xml how

您好 network_security_config 中是否可以有多个子域?

请参阅下面的示例:我找不到包含多个示例的任何示例。

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="false">
      <domain includeSubdomains="true">whatever.com</domain>
      <domain includeSubdomains="true">anotherone.com</domain>
    <pin-set>
        <pin digest="SHA-256">whatever.compinhere</pin>
        <pin digest="SHA-256">anotherone.compinhere/TLRbotnEw=</pin>
        <!-- backup pin -->
        <pin digest="SHA-256">backuppinwhatever.compinhere</pin>
       <pin digest="SHA-256">backuppinanotherone.compinhere/TLRbotnEw=</pin>
    </pin-set>
  </domain-config>
</network-security-config>

或者下面这个是否正确

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="false">
      <domain includeSubdomains="true">whatever.com</domain>
    <pin-set>
        <pin digest="SHA-256">whatever.com in here</pin>
        <!-- backup pin -->
    </pin-set>
  </domain-config>
  <domain-config cleartextTrafficPermitted="false">
        <domain includeSubdomains="true">anotherone.com</domain>
        <pin-set>
            <pin digest="SHA-256">anotherone.cominhere</pin>
            <!-- backup pin -->
        </pin-set>
  </domain-config>
</network-security-config>

以上哪一项是有效的方法? 非常感谢

根据官方文档,network_security_config可以包含任意数量的<domain-config><domain-config>可以包含0或者1,<pin-set>可以包含任意数量<pin>.

看来你提供的两个例子都是对的

如需更多信息,请查看官方文档: https://developer.android.com/training/articles/security-config