天天看點

【測試】Charles的map,rewrite,breakpoints的使用方法

charles的map映射

Map映射包含兩種一種是 Map Remote,另一種是 Map Local

Map Remote功能:将請求的域名重定向到另一個遠端URL
 Map Local功能:将請求的響應結果重定向到本地檔案中      

設定路徑:Tools -> Map Local/Remote

适用場景:Map适合長期的将某些請求重定向到另一個網絡位址或将響應的結果重定向到讀取本地檔案

Map Remote使用方法

【測試】Charles的map,rewrite,breakpoints的使用方法

map from 填寫源位址,端口号,路徑,以及請求參數

map to 填寫目标位址,端口号,路徑,以及請求參數

注意map to 公司内網的測試環境,可能不能進行dns解析,是以需要填寫ip位址+端口,不能直接填寫域名

【測試】Charles的map,rewrite,breakpoints的使用方法

注意preserve host in header fields這一項,可以保持map remote後的請求頭不改變,仍然使用原來的請求頭。可以和rewrite功能配合使用,例如:map remote生效後(原先請求tieba.baidu.com 打到10.xx.xx.xx:8085),再使用rewrite修改請求頭(比對請求頭中的host字段,需求是比對到tieba.baidu.com rewrite成tieba.xxx.baidu.com),這時候必須勾選preserve host in header fields這一項,不然host字段就會改成map remote之後的host 10.xx.xx.xx:8085,不然命中rewrite的規則

Map Local的使用方法

先進入map local的設定頁面,點選add

【測試】Charles的map,rewrite,breakpoints的使用方法

map local 的設定頁面,同樣需要設定protocol協定,域名(ip),端口号,請求路徑,請求參數。map local 由于是一個url對應一個傳回結果,是以請求參數需要完整填寫

【測試】Charles的map,rewrite,breakpoints的使用方法

map to的本地json檔案,可以通過以下方式進行擷取,右鍵要map local的url位址,點選save response結果。通常是json檔案,修改該json檔案的某些字段的值,即可實作本地mock資料的效果。

【測試】Charles的map,rewrite,breakpoints的使用方法

rewrite的使用方法

Rewrite可以:

修改請求頭(Add/Modify/Remove Header)

修改Host/Path/URL

修改請求參數(Add/Modify/Remove Query-Parameter)

修改響應狀态(Response Status)

修改Body

Rewrite設定路徑: Tools -> Rewrite

适用場景:支援臨時性修改請求頭或者傳回結果當中的某個字段

【測試】Charles的map,rewrite,breakpoints的使用方法
【測試】Charles的map,rewrite,breakpoints的使用方法

替換,支援正規表達式

【測試】Charles的map,rewrite,breakpoints的使用方法

rewrite功能詳細教程

​​​ https://www.testwo.com/blog/8495​​

breakpoints的使用方法

待補充

charles抓包問題及解決彙總