php - can't print response data after sending guzzle `get` request -
i able to data wanted using postman
after submitting url params: http://10.0.0.0/adserver/src/public?url=http://dummy.com
but when tried sending same request guzzle:
public function testgetads_test() { $client = new client(['base_uri' => $this->config['base_url']]); $response = $client->get('getads', ['query' => ['url' => 'http://dummy.com']]); $data = json_decode($response->getbody()); var_dump($response->getbody()); }
i 200 dump prints insead of data got using postman
:
.object(guzzlehttp\psr7\stream)#41 (7) { ["stream":"guzzlehttp\psr7\stream":private]=> resource(226) of type (stream) ["size":"guzzlehttp\psr7\stream":private]=> null ["seekable":"guzzlehttp\psr7\stream":private]=> bool(true) ["readable":"guzzlehttp\psr7\stream":private]=> bool(true) ["writable":"guzzlehttp\psr7\stream":private]=> bool(true) ["uri":"guzzlehttp\psr7\stream":private]=> string(10) "php://temp" ["custommetadata":"guzzlehttp\psr7\stream":private]=> array(0) { } }
any idea missing here?? thx
if deal json response can directly call json()
method on response object described here in doc:
so can use:
$data = $response->json();
guzzle internally uses php’s
json_decode()
function parse responses. if guzzle unable parse json response body, guzzlehttp\exception\parseexception thrown.
hope help
Comments
Post a Comment