调用博主最近登录时间
生活中的HYGGE
通过Fiddler抓包调试PHP内Guzzle网络请求
PHP

通过Fiddler抓包调试PHP内Guzzle网络请求

hygge
2022-09-10 / 0 评论 / 46 阅读 / 正在检测是否收录...

场景

最近在做设计素材网解析下载,后台框架使用Laravel

网络请求框架使用HTTP Client

Laravel provides an expressive, minimal API around the Guzzle HTTP client, allowing you to quickly make outgoing HTTP requests to communicate with other web applications. Laravel's wrapper around Guzzle is focused on its most common use cases and a wonderful developer experience.

一、Fiddler配置

HTTP 抓包

Fiddler 主菜单 -> Tools -> Fiddler Options-> Connections-> 选中 Allowremote computers to connect

装有 fiddler 的机器,找出能远程访问的 IP,一般局域网内也就是本机 IP。

被抓包调试的设备在网络代理那里启用代理 -> 代理 IP 就是上面说的 IP-> 端口号默认为 8888 (可以在 fiddler 中 Connections 标签页修改)
这样就 OK 了。

HTTPS 抓包

Fiddler 主菜单 -> Tool->Fiddler Options->HTTPS -> 选中 decrypt https traffic 和 ignore server certificate errors
会提示你安装证书,必要要安装。

然后同 HTTP 抓包一样操作

二、代码配置代理

$response = Http::withCookies(cookieStrToArray($cookie->content), 'nipic.cn')
            ->withOptions(
                [
                    'proxy' => '127.0.0.1:8888', // 端口为Fiddler中配置的端口
                    'verify' => false, // 禁用证书验证
                ])
            ->withHeaders([
                'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
                'Accept-Encoding' => 'gzip, deflate, br',
            ])
            ->withUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36')
            ->get("https://down.nipic.cn/download?id=$resourceId")->body();

再次请求可以看到Fiddler拦截到了请求。

l7vgr43c.png

三、使用Telescope

需要安装一下对应的依赖

# You may use the Composer package manager to install Telescope into your Laravel project:
composer require laravel/telescope --dev

# After installing Telescope, publish its assets using the telescope:install Artisan command. After installing Telescope, you should also run the migrate command in order to create the tables needed to store Telescope's data:

php artisan telescope:install
 
php artisan migrate

只有使用HTTP Client才会被记录,而且请求和响应的记录信息不太全,所以使用Fiddler还是更好的选择。

l7vgre41.png

引用

1.Fiddler 抓包调试 : https://www.chengxiaobai.cn/skills/fiddler-capture-debugging.html

2.laravel中使用Guzzle 报 unable to get local issuer certificate错误信息:https://blog.csdn.net/worldmakewayfordream/article/details/114302020

3.Guzzle 6 请求选项 :https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html

4.如何获取php向其它网站发起了什么请求,有什么办法?: https://learnku.com/laravel/t/67345

5.HTTP Client : https://laravel.com/docs/9.x/http-client

6.Laravel Telescope : https://laravel.com/docs/9.x/telescope

0

评论 (0)

取消