/** * Perform an JSOC-RPC request and return a response. * * @param Request $request Request. * @return Response Response. * @throws Exception\HttpException When HTTP communication fails. */ public function doRequest($request) { $this->lastRequest = $request; $httpRequest = $this->httpClient->getRequest(); if ($httpRequest->getUriString() === null) { $this->httpClient->setUri($this->serverAddress); } $headers = $httpRequest->getHeaders(); $headers->addHeaders(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); if (!$headers->get('User-Agent')) { $headers->addHeaderLine('User-Agent', 'Zend_Json_Server_Client'); } $this->httpClient->setRawBody($request->__toString()); $this->httpClient->setMethod('POST'); $httpResponse = $this->httpClient->send(); if (!$httpResponse->isSuccess()) { throw new Exception\HttpException($httpResponse->getReasonPhrase(), $httpResponse->getStatusCode()); } $response = new Response(); $this->lastResponse = $response; // import all response data form JSON HTTP response $response->loadJson($httpResponse->getBody()); return $response; }