使用uni-app开发的应用,安装后安卓使用charles抓包https失败,经测试手机浏览器上的https是可以正常抓取,所以问题定位到app本身上。
造成原因是android7.0以上系统不再默认信任用户安装的证书,需要修改manifest.xml。幸好uni-app在HX3.6版本起支持直接在应用中配置应用清单,文档见Android原生应用清单文件和资源 | uni-app官网
针对这个问题,具体修改步骤为
1、应用目录下添加自定义文件 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="cn.wywk.ylts">
<!--permissions-->
<application android:networkSecurityConfig="@xml/network_security_config">
</application>
</manifest>
2、添加网络配置文件 nativeResources/android/res/xml/network_security_config.xml
注意路径要按这个结构来
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" overridePins="true" />
<certificates src="user" overridePins="true" />
</trust-anchors>
</base-config>
</network-security-config>
3、重新生成自定义基座,运行到android设备。成功抓到https包