如何使用 Laravel 7+

问题描述

我正在使用

  • Laravel 框架 7.28.4
  • guzzlehttp/guzzle: "^7.2",
  • PHP 8.0.5

我正在使用 laravel 中的一些第三方 API Http Client

我需要什么:我需要在文件中记录每个请求和响应以进行跟踪以供进一步使用。

我关注了一些博客和答案。

1 https://medium.com/@sirajul.anik/logging-request-response-for-guzzle-bbea1f54cd87

[2] https://github.com/bilfeldt/laravel-http-client-logger

[3] Laravel - Log Guzzle requests to file

使用给定方法调用 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 调用如何登录文件中?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)