android使用Charles抓包https请求


按照正常抓http的方式进行抓包,会出现如下情况:

android使用Charles抓包https请求

https抓包就是需要在电脑端和移动端装上安全证书。

电脑端的安装:

android使用Charles抓包https请求android使用Charles抓包https请求android使用Charles抓包https请求

手机端就是需要到手机浏览器打开chls.pro/ssl下载安全证书安装到手机上,如下所示:android使用Charles抓包https请求

android使用Charles抓包https请求

再在青花瓷上设置一下SSL Proxying,7.0以下的android手机就能正常抓包了:

android使用Charles抓包https请求android使用Charles抓包https请求



但是在7.0的手机上还会出现以下情况:

android使用Charles抓包https请求

这是android7.0安全策略问题。手机持有者也没有权限,只有该应用自己设置安全证书,你才能抓到该应用的https数据。

添加安全配置文件

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >
        ...
    </application>
</manifest>

配置用于调试的 CA

在res文件夹下新建xml文件夹,再在xml文件夹下新建network_security_config.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <debug-overrides>
        <trust-anchors>
            <certificates src="@raw/debug_cas"/>
        </trust-anchors>
    </debug-overrides>
</network-security-config>
然后在res文件夹下新建raw文件夹,将手机上下载的安全证书重命名为"debug_cas"(没有后缀),并放到raw文件夹下。安全证书可到如下地址下载:http://www.charlesproxy.com/getssl/

最终就能正常抓包了。

参考链接

http://blog.****.net/u011045726/article/details/76064048

https://developer.android.google.cn/training/articles/security-config.html#CustomTrust