I use Guzzle to create an aSync request that returns JSON. The call is working fine and the answer is ok, however:
$client = new Client();
$promise = $client->requestAsync($requestType ,$this->url.$resource,
[
'auth' => [
$this->username,
$this->password
],
'json' => $payload,
'curl' => [
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_RETURNTRANSFER => true,
],
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json'
]
]
);
$response = $promise->wait();
echo $response->getStatusCode().'<br /><br />';
if($response->getStatusCode() != 200){
}else{
echo $response->getBody(true);
}
if echo response-> getBody () I see a JSON string, but if I assign it to the print_r property or return it, I get:
GuzzleHttp\Psr7\Stream Object ( [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #245 [size:GuzzleHttp\Psr7\Stream:private] => [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [readable:GuzzleHttp\Psr7\Stream:private] => 1 [writable:GuzzleHttp\Psr7\Stream:private] => 1 [uri:GuzzleHttp\Psr7\Stream:private] => php:
I need to use JSON to check my response from the service. How can i do this? I went through the documents, but I obviously missed something.
Essentially, by destination json getBody output, to say $ json:
if($json->first_field > 0)
Any help appreciated. Relations
source
share