Memanggil kaedah yang tidak ditentukan GuzzleHttp\Command\Result::getBody()
<p>Saya cuba mendapatkan respons dalam format json daripada API luaran dalam Drupal. Saya menggunakan modul Drupal Pengurus Pelanggan HTTP.
Sekarang saya hanya boleh mendapatkan respons dalam format objek stdClass dalam tatasusunan dan semua nilai kunci respons hilang. </p>
<p>Kod asal saya: </p>
<pre class="brush:php;toolbar:false;">public function findPosts() {
$client = $this->getClient();
$params = array('client_Id' => "12345",
"Rahsia_pelanggan" ="42452454",
"skop" ="baca";
$respons = $client->FindPosts($params);
dpm($respon);
kembalikan ['#markup' =>
}</pre>
<p>Keluarkan kod berikut. Saya juga memerlukannya untuk kelihatan seperti [access_token] => eyJhbGciOiJIUzUxMiIsIn, [type] => pembawa dll. </p>
<pre class="brush:php;toolbar:false;">stdClass Object
(
[__CLASS__] => GuzzleHttpCommandResult
[data:protected] => Tatasusunan
(
[0] =>eyJhbGciOiJIUzUxMiIsIn
[1] =>
[2] =>
[3] => 2022-11-09T10:48:47+00:00
[4] => baca
[5] => MwA1ADkAZAA0AGIAZA4AC0AOQAzADcA
[6] =>
[7] => 2022-11-10T09:48:47+00:00
)
)</pra>
<p>Apabila saya mencuba $response->getBody() atau $response->getContent() atau sebarang kaedah respons lain, ia mengembalikan ralat berikut.</p>
<pre class="brush:php;toolbar:false;">Ralat: Panggilan ke kaedah yang tidak ditentukan GuzzleHttpCommandResult::getBody() dalam Drupalhttp_client_manager_exampleControllerExampleController->findPosts() (baris 92/modul_client_manager/clientamplemana /src/Controller/ExampleController.php).
Drupalhttp_client_manager_exampleControllerExampleController->findPosts()
call_user_func_array(Array, Array) (Barisan: 123)
DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->DrupalCoreEventSubscriber{closure}() (Barisan: 564)
DrupalCoreRenderRenderer->executeInRenderContext(Objek, Objek) (Baris: 124)
DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Baris: 97)
DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->DrupalCoreEventSubscriber{closure}() (Barisan: 169)
SymfonyComponentHttpKernelHttpKernel->handleRaw(Objek, 1) (Barisan: 81)
SymfonyComponentHttpKernelHttpKernel->handle(Objek, 1, 1) (Barisan: 58)
DrupalCoreStackMiddlewareSession->handle(Objek, 1, 1) (Barisan: 48)
DrupalCoreStackMiddlewareKernelPreHandle->handle(Objek, 1, 1) (Barisan: 106)
Drupalpage_cacheStackMiddlewarePageCache->pass(Objek, 1, 1) (Baris: 85)
Drupalpage_cacheStackMiddlewarePageCache->handle(Objek, 1, 1) (Barisan: 49)
Asm89StackCors->handle(Objek, 1, 1) (Barisan: 48)
DrupalCoreStackMiddlewareReverseProxyMiddleware->handle(Objek, 1, 1) (Barisan: 38)
DrupalwebprofilerStackMiddlewareWebprofilerMiddleware->handle(Objek, 1, 1) (Barisan: 51)
DrupalCoreStackMiddlewareNegotiationMiddleware->handle(Objek, 1, 1) (Barisan: 23)
StackStackedHttpKernel->handle(Objek, 1, 1) (Barisan: 709)
DrupalCoreDrupalKernel->handle(Objek) (Baris: 19)</pre></p>