今天測試小哥思彬說我只有一篇 iOS 篇的抓包文章,為啥沒有安卓的。。。理論上,它和蘋果是一樣,以前也確實(shí)可以抓取 https,事實(shí)上,我后面再試了幾次,沒成功就沒管了。。。此時測試小哥仿佛要向我吐一口濃痰,心里默念著 你個垃雞、菜B。。?;谖仪皫状螠y試都失敗了,今天和測試小哥決定再抓不了 Android 的 https 請求,就不回家了,由我來負(fù)責(zé)監(jiān)督他睡公司!哈哈,是個狠人!
-
設(shè)置 fiddler ,勾上捕捉 HTTPS 鏈接等操作
fiddler設(shè)置 -
安裝 fiddler 證書。此處 Android 眾多機(jī)型,安裝最終以下圖為基準(zhǔn),因?yàn)閭€別手機(jī)無法直接在瀏覽器打開下載的 FidderRoot.cer 文件,所以最終辦法是找到下載的文件所在位置,直接打開安裝
無法直接打開證書

-
此時,按照以前我抓包的情況,這樣就可以抓了??墒乾F(xiàn)在不行了,為什么呢?主要問題是
Android 7系統(tǒng)之后加入了網(wǎng)絡(luò)安全配置,Android 7系統(tǒng)之前的無視以下操作,否則需要開發(fā)人員配合導(dǎo)入證書,這是 Android 7 官方說明 https://developer.android.google.cn/about/versions/nougat/android-7.0
Android 7 官方說明 -
需要開發(fā)人員在代碼配置證書,配置證書官方說明 https://developer.android.com/training/articles/security-config?hl=en
代碼配置證書 我本代碼配置
network-security-config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
<domain includeSubdomains="true">******</domain> // 此處是項(xiàng)目域名,按真實(shí)各位真實(shí)域名填寫,我這寫*號只是展示
<trust-anchors>
<certificates src="@raw/fiddler_root"/>
</trust-anchors>
</domain-config>
</network-security-config>
-
AndroidManifest.xml配置,關(guān)鍵是android:networkSecurityConfig="@xml/network_security_config",其它不用看
<application
android:name=".app.MLApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/pdd_icon"
android:label="@string/app_name"
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/pdd_icon"
android:supportsRtl="true"
android:theme="@style/Theme.MaiLang"
android:usesCleartextTraffic="true">
.......// 省略代碼
</application>
-
經(jīng)過如上問題的排查和配置,現(xiàn)在就可以抓取 Android 的 https 請求了
抓取圖
iOS 篇請?zhí)D(zhuǎn)此地址:http://www.itdecent.cn/p/8d0ee661c74c




