Exemplo n.º 1
0
 /**
  * Sends a request to pull data from X2Engine, or to delete/unsubscribe.
  *
  * @param string $method Request method to use
  * @param array $data an array to JSON-encode and send
  */
 public function send($method, $data)
 {
     if (!extension_loaded('curl')) {
         return;
     }
     // Compose the body of the request to send
     $payload = json_encode($this->walkData($data));
     // Start a cURL session and configure the request
     $this->_ch = curl_init($this->target_url);
     curl_setopt_array($this->_ch, array(CURLOPT_CUSTOMREQUEST => $method, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => $this->getTimeout(), CURLOPT_HTTPHEADER => array('Content-Type: application/json; charset=utf-8'), CURLOPT_HTTP200ALIASES => array_keys(ResponseUtil::getStatusMessages())));
     if (!empty($payload)) {
         curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $payload);
     }
     // Send the request
     $this->sent = curl_exec($this->_ch);
     // If the remote end is no longer listening, we can stop sending data
     if ($this->getStatus() == 410) {
         $this->setScenario('delete.remote');
         $this->delete();
     }
 }
Exemplo n.º 2
0
 public function getHttp200Aliases()
 {
     return array_keys(ResponseUtil::getStatusMessages());
 }