_httpClient instanceof Zend_Http_Client) { //$this->_httpClient = $this->_httpClient; } else { $this->_httpClient = new Zend_Http_Client(); $this->_httpClient->setConfig(array( 'adapter' => 'Zend_Http_Client_Adapter_Curl', 'maxredirects' => 0, 'timeout' => 60, 'ssltransport' => 'ssl' )); $this->_httpClient->setHeaders('Authorization', 'key=' . self::SECRET_ID); } } /***** METODI COMUNI DELLE CHIMATE *****/ public function postCall($dati) { $this->_httpClient->setMethod('POST'); $this->_httpClient->setUri($this->getBaseUrl() . '/send'); $this->_httpClient->setRawData(Zend_Json::encode($dati), 'application/json;charset=utf-8'); return $this->executeCall(); } /***** METODI PRIVATI PER GESTIRE LE CHIAMATE *****/ private function getBaseUrl() { return self::BASE_API_URL . "/" . self::API_VERSION; } private function executeCall() { $httpResponse = $this->_httpClient->request(); /*if($this->_ipManager->allowedIp()){ Zend_Registry::get('log')->info(print_r($httpResponse,true)); }*/ // Zend_Registry::get('log')->info(print_r($this->_httpClient->getLastRequest(), true)); $httpResponseEncoded = json_decode($httpResponse->getBody(), 1); // Zend_Registry::get('log')->info(print_r($httpResponseEncoded, true)); if (json_last_error() !== JSON_ERROR_NONE) { Zend_Registry::get('log')->info($this->_httpClient->getUri()); Zend_Registry::get('log')->info("Errore codifica JSON:"); Zend_Registry::get('log')->info(print_r($httpResponse, true)); return null; } if ($this->_httpClient->getLastResponse()->getStatus() != '200' || $httpResponseEncoded['status'] == 'error') { Zend_Registry::get('log')->info($this->_httpClient->getUri()); Zend_Registry::get('log')->info("Errore status response " . $this->_httpClient->getLastResponse()->getStatus()); Zend_Registry::get('log')->info(print_r($httpResponseEncoded, true)); throw new App_Exception_ResponseCloudException($httpResponseEncoded['message'], $httpResponseEncoded['errorCode']); } return $httpResponseEncoded; } }