在targetSdkVersion >=27
的app运行在android 9时如果是http请求会报错,解决办法是添加xml设置 res/xml/network_security_config
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
在AndroidManifest.xml
中配置
<application
android:name=".AppApplication"
android:allowBackup="true"
android:icon="@mipmap/icon_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar"
android:networkSecurityConfig="@xml/network_security_config" >
就能解决无法请求http请求了