【问题标题】:Android - Use retrofit2 to request dynamic IP addressAndroid - 使用 retrofit2 请求动态 IP 地址
【发布时间】:2021-02-11 23:39:04
【问题描述】:

使用 Retrofit2 执行网络请求,现在尝试调用可配置 IP 的服务,但我得到了CLEARTEXT communication to **IP_ADDRESS*** not permitted by network security policy

我在论坛上看到我们可以将 IP 地址添加到network_security_config.xml,但我需要动态地址。还尝试在清单中添加标志 usesCleartextTraffic 但同样的错误引发(在 Android 10 上测试)

如何请求动态 IP 地址而无需在 network_security_config.xml 中指定?

【问题讨论】:

    标签: android retrofit2 cleartext


    【解决方案1】:

    为 network_security_config.xml 使用下面的 xml 代码

    <network-security-config>
        <base-config cleartextTrafficPermitted="true">
            <trust-anchors>
                <certificates src="system" />
            </trust-anchors>
        </base-config>
    </network-security-config>
    

    它应该工作! 对不起我的英语不好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-21
      • 2011-07-31
      • 1970-01-01
      • 2017-06-30
      • 2015-12-14
      • 2018-07-04
      • 2015-04-16
      • 2013-01-23
      相关资源
      最近更新 更多