安卓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
亲测有效,模拟器就是用这个办法跑通的,真机不需要