Recently, the app was running in Android 9 On the device , find http There was no response from the network request .

Official information mentioned in framework security change , The address is :

Network transport layer security protocol is enabled by default (TLS)

If your app uses Android 9 Or later is the target platform , By default  isCleartextTrafficPermitted()
  Function return  false. If your application needs to enable clear text for a specific domain name , You must configure the network security in the application
For these domain names, the  cleartextTrafficPermitted  Explicitly set to  true.

The specific solution consists of two steps , The references are :


The first step : In the manifest file AndroidManifest.xml Of application Inside the label networkSecurityConfig The properties are as follows :
<?xml version="1.0" encoding="utf-8"?> <manifest ... > <application
android:networkSecurityConfig="@xml/network_security_config"> <!-- ... -->
</application> </manifest>
Step two : In Resources folder res/xml Create network_security_config.xml as follows :
<?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>