在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)