Android | 允许 http 请求 允许应用程序使用Http明文网络传输

Android | 允许 http 请求 允许应用程序使用Http明文网络传输

王先生
2024-06-26 / 0 评论 / 21 阅读 / 正在检测是否收录...

在res/xml目录下新建xml文件,命名network_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted = "true">
        <trust-anchors>
            <certificates src="system"/>
        </trust-anchors>
    </base-config>
</network-security-config>

修改Manifest文件以启动刚才创建的配置文件:

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.NetUtils"
        android:networkSecurityConfig="@xml/network_config"
        tools:targetApi="31">

划重点:

android:networkSecurityConfig="@xml/network_config"

评论 (0)

取消