【问题标题】:how to get http request detail in laravel?如何在 laravel 中获取 http 请求详细信息?
【发布时间】:2021-11-29 05:43:22
【问题描述】:

我有一个这样的 http 客户端请求?

        try {
           $request = json_encode($data);
           $result = $this->pendingRequest->{$method}('http://test.local/general/wallets/1000000', $data);
           // this is my request detail
           $request = $result->transferStats ? Message::toString($result->transferStats->getRequest()) : $request;
           $result->throw();
           $this->setLog($provider, $step, $request, $result->body(), $url, $result->status());
           return $result;
         } catch (RequestException $exception) {
          // I need to http request detail            
         } catch (ConnectionException $exception) {
          // I need to http request detail
         }

我需要获取我的请求参数、标头和令牌以及在缓存异常中发送给第三方的所有内容。我可以通过以下方式尝试获取详细信息:Message::toString($result->transferStats->getRequest())

【问题讨论】:

    标签: php laravel lumen


    【解决方案1】:

    你可以把它当作

    $request->all();
    

    如果你想看到更多规则。你可以试试

    dd($request->all());
    

    【讨论】:

      【解决方案2】:

      Illuminate\Http\Client\Request

      headers() : array

      • 获取请求标头。

      parameters() : array

      • 获取请求的表单参数。

      body() : string

      • 获取请求的正文。

      data() : array

      • 获取请求的数据(表单参数或 JSON)。

      【讨论】:

      • 所有这些都写在 laravel 文档中。我需要这样的代码:Message::toString($result->transferStats->getRequest())。你用过这段代码吗?
      • @mohammadnabipour ,您是指访问catch... 块中的$request 变量吗?
      【解决方案3】:

      你可以@dd($request); 在刀片上或 dd($请求);在控制器等上。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-23
        • 2018-09-20
        • 1970-01-01
        • 1970-01-01
        • 2020-07-08
        • 1970-01-01
        • 2016-12-02
        • 1970-01-01
        相关资源
        最近更新 更多