解决Andriod使用HttpURLConnection 失败问题

1、AndroidManifest.xml配置网络权限:

xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.yw.hello2">
    
            android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:usesCleartextTraffic="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        android:name=".MainActivity">
            
                android:name="android.intent.action.MAIN" />

                android:name="android.intent.category.LAUNCHER" />
            
        
        android:name=".Page1Activity">
    

2、创建res/xml/network_security_config.xml

xml version="1.0" encoding="utf-8"?>

    cleartextTrafficPermitted="true" />


你可能感兴趣的:(linux,互联网)