/** * Send a request encoded in the format defined by the ACME protocol. * * @param string $method * @param string $endpoint * @param array $data * @param bool $returnJson * * @throws AcmeCoreServerException When the ACME server returns an error HTTP status code. * @throws AcmeCoreClientException When an error occured during response parsing. * * @return array|string Array of parsed JSON if $returnJson = true, string otherwise */ public function unsignedRequest($method, $endpoint, array $data = null, $returnJson = true) { $request = $this->createRequest($method, $endpoint, $data); try { $this->lastResponse = $this->httpClient->send($request); } catch (\Exception $exception) { $this->handleClientException($request, $exception); } $body = \GuzzleHttp\Psr7\copy_to_string($this->lastResponse->getBody()); if ($returnJson) { $data = @json_decode($body, true); if (!$data) { throw new ExpectedJsonException(sprintf('ACME client excepted valid JSON as a response to request "%s %s" (given: "%s")', $request->getMethod(), $request->getUri(), ServerErrorHandler::getResponseBodySummary($this->lastResponse))); } return $data; } return $body; }