Lompat ke konten Lompat ke sidebar Lompat ke footer

Cara mengambil Response Body Web Service Guzzle PHP

Method getBody() hanya menampilkan

GuzzleHttp\Psr7\Stream Object ( [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #14 [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 ( ) )

Old syntax

 try {
            $client = new GuzzleHttp\Client([
                'timeout' => 5,
                'allow_redirects' => false
            ]);

            $response = $client->request('GET', 'http://httpbin.org/get',
                    ['nama_lengkap' => $nama]
            );
            $service_output = $response->getBody();
            print_r($service_output);exit(); 

} catch (Exception $ex) {
            $output['message'] = $ex->getMessage();
        }

New syntax

try {
            $client = new GuzzleHttp\Client([
                'timeout' => 5,
                'allow_redirects' => false
            ]);

            $response = $client->request('GET', 'http://httpbin.org/get',
                    ['nama_lengkap' => $nama]
            );
            $service_output = $response->getBody()->getContents();
            print_r($service_output);exit(); 

} catch (Exception $ex) {
            $output['message'] = $ex->getMessage();
        }

Posting Komentar untuk "Cara mengambil Response Body Web Service Guzzle PHP"