【问题标题】:Guzzle getBody() after request return posted body请求返回发布的正文后 Guzzle getBody()
【发布时间】:2018-06-08 23:21:28
【问题描述】:

我正在使用 Guzzle 6.3。我正在尝试发布带有标题的数据。 这是我的代码:

$headers = [
  'content-type' => 'application/json',
  'Accept' => 'application/json'
];

$request = new Psr7\Request('post', 'product', $headers, json_encode($data));
$res = $this->http->send($request);
$resData = json_decode($res->getBody(), true);

响应正文 ($resData) 始终等于发布的正文 ($data)。

谢谢。

【问题讨论】:

    标签: guzzle6 guzzle


    【解决方案1】:

    试试

    $resData = json_decode($res->getBody()->getContents(), true);
    

    否则(如果没有帮助)检查您的 API 端点返回的内容。

    【讨论】:

      猜你喜欢
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      相关资源
      最近更新 更多