我不知道为什么Guzzle的客户只返回"结果"值。如何获得完整的响应数据。
(1)method_A返回结果。 Guzzle的客户端返回结果。这没问题。
// HTTP request with curl
curl -X POST --data '{"jsonrpc":"2.0","method":"method_A","params":["xxx"],"id":1}' https://example.com/rpc
{"jsonrpc":"2.0","id":1,"result":"0x5209"}
// HTTP request with Guzzle
$client = new Client(['base_uri' => 'https://example.com/rpc']);
$response = $client->request('POST', '', ['json' => $params]);
echo json_encode($response) // 0x5209
(2)method_B返回错误。 Guzzle的客户端返回空而不是错误。这是我的问题。
// HTTP request with curl
curl -X POST --data '{"jsonrpc":"2.0","method":"method_B","params":["xxx"],"id":1}' https://example.com/rpc
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"nonce too low"}}
// HTTP request with Guzzle
$client = new Client(['base_uri' => 'https://example.com/rpc']);
$response = $client->request('POST', '', ['json' => $params]);
echo json_encode($response) // empty
FYI。 https://example.com/rpc返回总是200个响应,即使响应数据由于某些原因而出错。
更新1
我尝试了以下内容。
Log::info($response);
Object of class GuzzleHttp\Psr7\Response could not be converted to string
Log::info(json_decode($response));
json_decode() expects parameter 1 to be string, object given
Log::info(var_dump($response));
<pre class='xdebug-var-dump' dir='ltr'>
<b>object</b>(<i>GuzzleHttp\Psr7\Response</i>)[<i>374</i>]
<i>private</i> 'reasonPhrase' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'OK'</font> <i>(length=2)</i>
...