安卓P之後不支持http明文傳輸了
有2個解決方案
1.可以在manifest 的application中加入
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
2.可以再res 目錄下新建一個xml文件夾
然後定義一個xml文件
輸入
<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:android="http://schemas.android.com/apk/res/android">
<base-config cleartextTrafficPermitted="false"/>
</network-security-config>
編譯環境跳到28以下
android { compileSdkVersion 28 buildToolsVersion "28.0.0" defaultConfig { applicationId "com.demo.mianshi" minSdkVersion 23 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }
如果以上還不行 !!!
請把http改成https
親測有效,模擬器就是用這個辦法跑通的,真機不需要