The solution to the failure of Android9.0 to access http
Reason: Android9.0
All http requests are prohibited by default
Methods 1 and 2 are mutually exclusive, do not set them at the same time! ! !
Solution 1:
Add AndroidManifest.xml
to the <application/>
tags in the fileandroid:usesCleartextTraffic="true"属性
Solution 2 (recommended to use this method):
① res
Create a new xml
folder named in the directory, and create a xml
new network_security_config.xml
file in:
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:android="http://schemas.android.com/apk/res/android">
<base-config cleartextTrafficPermitted="true"/>
</network-security-config>
② Then <application/>
add android:networkSecurityConfig="@xml/network_security_config"
attributes to the label