laravel - 如何使用 Laravel 7+ 在文件中记录 Guzzle Http 请求响应
问题描述
我在用
- Laravel 框架 7.28.4
- guzzlehttp/guzzle: "^7.2",
- PHP 8.0.5
我正在使用Http Client在 laravel 中使用一些第三方 API
我需要什么:我需要在文件中记录每个请求和响应以跟踪以供进一步使用。
我正在关注一些博客和答案。
1 https://medium.com/@sirajul.anik/logging-request-response-for-guzzle-bbea1f54cd87
[2] https://github.com/bilfeldt/laravel-http-client-logger
使用给定方法调用 web.php 时,上述 [3] 链接的工作方式如前所述。 这有效
$client = app('GuzzleClient')([
'base_uri' => 'https://jsonplaceholder.typicode.com/',
'timeout' => 10,
'verify' => false,
]);
$request = $client->get('users', [
'headers' => [ 'accept' => 'application/json']
]);
$response = json_decode((string) $request->getBody());
但是我正在使用这样的 HTTP 类来使用这个单行 API 调用,我不会自己创建任何新对象。
$response = Http::withBody(
json_encode($reqArray), 'application/json')->withToken($token)->post($SearchByNameApi);
有人可以帮助实现这一点,我的 API 调用如何登录到文件中?
解决方案
推荐阅读
- postgresql - 为什么这些 SQL 表达式中的时区没有变化?
- angular - 你能在 Angular 中禁用辅助/辅助路由吗?
- image - SharePoint 365 将图像链接到电子邮件模板
- string-view - gsl::string_span 和 std::string_view 有何不同?
- oracle - 如何允许其他用户访问我的架构
- c# - InPlaceBitmapMetadataWriter 在将关键字从最近的相机中写入照片时失败
- instagram - 如何获得 Instagram 访问令牌?
- css - 如何更改 mat-table 内 ng-container 的宽度
- image - 图像延迟加载 Ionic 3
- reactjs - 子屏幕中的 React-Native 导航?