php - How to return Guzzle JSON response -


i using guzzle make async request returns json. call working fine , response ok, however:

$client = new client();     $promise = $client->requestasync($requesttype ,$this->url.$resource, // endpoint         [             'auth' => [ // credentials                 $this->username,                  $this->password             ],             'json' => $payload, // package             'curl' => [ // curl options                 curlopt_httpauth => curlauth_basic,                 curlopt_returntransfer => true,             ],             'headers' => [ // custom headers                 'accept' =>  'application/json',                 'content-type' => 'application/json'             ]         ]     );      $response = $promise->wait();     echo $response->getstatuscode().'<br /><br />';     // error handling     if($response->getstatuscode() != 200){         // error handling     }else{         echo $response->getbody(true);     } 

if echo response->getbody() see json string, if assign property, print_r, or return 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://temp [custommetadata:guzzlehttp\psr7\stream:private] => array ( ) ) 

i need use json validate response service. how can this? have gone through docs, missing something.

essentially along lines of assigning json getbody output $json:

if($json->first_field > 0) 

any appreciated. regards

after more research on tumbled head first post

guzzle 6: no more json() method responses

essentially doing following return raw output.

return $response->getbody()->getcontents(); 

huge headache gone. hope helps someone


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -