自Android9.0系统开始,应用程序默认只允许使用HTTPS类型的网络请求,HTTP类型的网络请求因为有安全隐患默认不再支持。为了让应用程序支持HTTP请求,可以做如下设置:
1、在res/xml目录下新建xml文件,命名network_config.xml
2、修改新建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>
3、修改Manifest文件以启动刚才创建的配置文件:
<application
android:name=".SophixStubApplcation"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="${app_icon}"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:networkSecurityConfig="@xml/network_config">
划重点:
android:networkSecurityConfig="@xml/network_config"