The solution to the failure of Android9.0 to access http

The solution to the failure of Android9.0 to access http

Reason: Android9.0All 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.xmlto the <application/>tags in the fileandroid:usesCleartextTraffic="true"属性

Solution 2 (recommended to use this method):

resCreate a new xmlfolder named in the directory, and create a xmlnew network_security_config.xmlfile 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

Guess you like

Origin blog.csdn.net/C_biubiubiu/article/details/110871708