Android 28 使用http请求报错 not not permitted by network security policy

Android 28 使用http请求报错 not not permitted by network security policy

java.net.UnknownServicrviceException: CLEARTEXT communication to to 127.0.0.1 not not permitted by network security policy

1、res/xml,增加network_security_config.xml。

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

2、AndroidManifest.xml,增加android:networkSecurityConfig=”@xml/network_security_config”。

<application
    android:name="CtsApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:networkSecurityConfig="@xml/network_security_config">

 

发表回复

您的电子邮箱地址不会被公开。