Charles https 红米手机抓包
1,设置charles 代理

2,手机设置代理

3. 手机访问 chls.pro/ssl
打开chrome或者火狐访问 chls.pro/ssl 安装证书,尽量别用系统浏览器,如果下载的证书是后缀名是.pem,请改成.crt。
4,手机安装证书
(miui10及以上)点击设置 ==> 更多设置 ==> 系统安全 ==> 加密与凭据 ==> 从存储卡安装文件
(miui10一下)点击设置 ==> 更多设置 ==> 系统安全 ==> 从存储卡安装文件
(红米4X) 打开设置 ==> 更多设置 ==> 系统安全 ==> 从存储设备安装证书 ==> 选择刚下载的charles证书。 如果提示需要输入密码,请回到安全设置中设置锁屏密码。

4 测试
打开需要抓包的APP,通过charles可以看响应体,表示成功了。
5 添加代码
打开APP,如果出现 java.security.cert.CertPathValidatorException: Trust anchor for certification path not found 这个异常,则需要添加代码到项目中。
添加如下文件 res/xml/network_security_config.xml 到你的代码里面:
<network-security-config>
<debug-overrides>
<trust-anchors>
<!-- Trust user added CAs while debuggable only -->
<certificates src="user" /> </trust-anchors>
</debug-overrides>
</network-security-config>
然后在你 app的 manifest 文件中引入上面的文件, 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config" ... > ... </application>
</manifest>
重新编译运行项目,就可以看到抓包成功啦!