如何接收使用 guzzle 发送的 post 方法的响应

how to recive the response of a post method send with guzzle

我正在用 guzzle 调用 api 并发送一些数据,api return 我想接收并显示一些数据,所以这是我的代码:

$requestapi = $client->post('http:url/api/v1/transaction/Verify', [
        'headers' => ['Content-Type' => 'application/json'],
        'body' => '{
        "tn":"1905463527",
        }'
    ]);

现在,当我添加 $requestapi 时,它现在向我显示验证 api return 的结果,并且只向我显示 200 响应。

GuzzleHttp\Client::post 方法 returns GuzzleHttp\Psr7\Response 对象。 您可以简单地使用 getBody 方法来访问响应主体。

$response = $client->post(...);
$contents = $response->getBody()->getContents();