Merge pull request #9559 from nextcloud/backport/9554/stable25

[stable25] docs: mention IResponse's getBody(), slash when catching Exception
This commit is contained in:
Daniel 2023-01-15 23:17:37 +01:00 committed by GitHub
commit cf8708b04f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@ HTTP client instances are built using the client service `factory <https://en.wi
public function downloadNextcloudWebsite(): void {
$client = $this->clientService->newClient();
$response = $client->get('https://nextcloud.com');
$body = $response->getBody();
}
}
@ -36,6 +37,7 @@ HEAD request
$client = $this->clientService->newClient();
$response = $client->head('https://nextcloud.com');
$body = $response->getBody();
GET request
@ -47,6 +49,7 @@ GET request
$client = $this->clientService->newClient();
$response = $client->get('https://nextcloud.com');
$body = $response->getBody();
POST request
------------
@ -68,7 +71,7 @@ POST request
],
])
]);
$pizza = json_decode($response, true);
$pizza = json_decode($response->getBody(), true);
PUT request
-----------
@ -90,7 +93,7 @@ PUT request
],
])
]);
$pizza = json_decode($response, true);
$pizza = json_decode($response->getBody(), true);
DELETE request
--------------
@ -129,6 +132,6 @@ Errors are signaled with exceptions. Catch PHP's base ``Exception``.
$client = $this->clientService->newClient();
try {
$response = $client->options('https://nextcloud.com');
} catch (Exception $e) {
} catch (\Exception $e) {
// Handle the error
}
}