在日常的工作中,我经常使用charles 来分析http请求,它非常的强大,可以去官网下载 https://www.charlesproxy.com/
需要注意charles是一款收费软件,但是你可以免费使用,只不过需要忍受启动加载慢的过程。

设置为系统代理
1.安装完毕后启动,然后选择Proxy-macOS Proxy

PC抓包
就可以把系统的http请求代理到charles了,如果你需要分析https的数据包,点击help- SSL proxying- INSTALL charles root certificate 安装


默认情况下选项卡是在Structur上,他会安装网站的域名进行分组

你可以切换到Sequence上查看所有的未分组请求的状态、请求方法、主机地址,请求URL路径等等

如果你只希望抓取某个域名的数据包,可以选择Porxy-Recording Setting,然后切换到Include

然后输入协议 hosts 端口即可

当你点击某一个请求包的时候,下面会显示你的请求信息和响应信息以及http的body体内容,可以通过过滤器过滤你的域名方法等等。

移动端抓包
选择Proxy- Proxy Settings,填写端口,假设本机地址是10.0.1.15,那么就去移动端设置代理

然后移动端,以iphone为例,点击设置 无线网 找到你链接的wifi,注意wifi必须与pc同网段,然后选择http代理 手动,填写服务器和端口

此时pc端会弹出一个对话框

然后就可以看到了移动端的请求了

查看请求文件的实体内容

注意:如果没有发现数据包,很可能是设置了Recording Setting 只运行某个域名的包通过了,通常链接后注意看下方状态是否有类似GET POST请求URL 一闪而过,如果有说明是请求了但是不匹配你的url所以忽略了。另外,移动端抓取SSL的包,需要安装证书,具体方法是点击help- SSL proxying- INSTALL charles root on a Mobile certificate Device or Remote Browser 安装

然后会弹出个对话框

你在移动端打开浏览器输入chls.pro/ssl 去下载文件安装,然后输入密码确认后完成安装。

安装完后进入系统-通用-关于本机 证书信任设置,针对根证书启动完全信任 开启charles Porxy CA
