Example #1
0
 public static function send()
 {
     $me = new self("global");
     $sent = array();
     $pastlink = new FutureLink_PastUI();
     $feed = $pastlink->feed();
     $items = array();
     //we send something only if we have something to send
     if (empty($feed->feed->entry) == false) {
         foreach ($feed->feed->entry as &$item) {
             if (empty($item->futurelink->href) || isset($sent[$item->futurelink->hash])) {
                 continue;
             }
             $sent[$item->futurelink->hash] = true;
             $client = new Zend\Http\Client($item->futurelink->href, array('timeout' => 60));
             if (!empty($feed->feed->entry)) {
                 $client->setParameterPost(array('protocol' => 'futurelink', 'metadata' => json_encode($feed)));
                 try {
                     $client->setMethod(Zend\Http\Request::METHOD_POST);
                     $response = $client->send();
                     $request = $client->getLastResponse();
                     $result = $response->getBody();
                     $resultJson = json_decode($response->getBody());
                     //Here we add the date last updated so that we don't have to send it if not needed, saving load time.
                     if (!empty($resultJson->feed) && $resultJson->feed == "success") {
                         $me->addItem(array('dateLastUpdated' => $item->pastlink->dateLastUpdated, 'pastlinklinkHash' => $item->pastlink->hash, 'futurelinkHash' => $item->futurelink->hash));
                     }
                     $items[$item->pastlink->text] = $result;
                 } catch (Exception $e) {
                 }
             }
         }
         return $items;
     }
 }
 {
     return in_array(strtolower($needle), array_map('strtolower', $haystack));
 }
 /**
  Please send me: array( 'uri'=> '', 'method'=>''[, 'curloptions'=> array( ... ) ])
  I will throw an Exception if something goes wrong so no need to validate
  But you can decide whether you wnat me to do it or not
  */
 public static function sendRequest($arrayParms, $throwEx = true)
 {
     Utils::arrayKeyExists(array('url', 'method'), $arrayParms);
     $client = new \Zend\Http\Client($arrayParms['url']);
     $client->setMethod($arrayParms['method']);
     switch ($arrayParms['method']) {
         case POST:
             Utils::arrayKeyExists('payload', $arrayParms);
             $client->setParameterPost($arrayParms['payload']);
             break;
         case GET:
             Utils::arrayKeyExists('payload', $arrayParms);
             $client->setParameterGet($arrayParms['payload']);
             break;
     }
     $adapter = new \Zend\Http\Client\Adapter\Curl();
     $curloptions = array(CURLOPT_POST => 1, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE);
     if (array_key_exists('curloptions', $arrayParms)) {
         $curloptions = array_merge($curloptions, $arrayParms['curloptions']);
     }
     $adapter->setOptions(array('curloptions' => $curloptions));
     $client->setAdapter($adapter);
     $response = $client->send();
     if ($response->isSuccess()) {
Example #3
0
 /**
  * Performs HTTP request to given $url using given HTTP $method.
  * Send additinal query specified by variable/value array,
  * On success returns HTTP response without headers, false on failure.
  *
  * @param string $url OpenID server url
  * @param string $method HTTP request method 'GET' or 'POST'
  * @param array $params additional qwery parameters to be passed with
  * @param int &$staus HTTP status code
  *  request
  * @return mixed
  */
 protected function _httpRequest($url, $method = 'GET', array $params = array(), &$status = null)
 {
     $client = $this->_httpClient;
     if ($client === null) {
         $client = new \Zend\Http\Client($url, array('maxredirects' => 4, 'timeout' => 15, 'useragent' => 'Zend_OpenId'));
     } else {
         $client->setUri($url);
     }
     $client->resetParameters();
     if ($method == 'POST') {
         $client->setMethod(\Zend\Http\Client::POST);
         $client->setParameterPost($params);
     } else {
         $client->setMethod(\Zend\Http\Client::GET);
         $client->setParameterGet($params);
     }
     try {
         $response = $client->request();
     } catch (\Exception $e) {
         $this->_setError('HTTP Request failed: ' . $e->getMessage());
         return false;
     }
     $status = $response->getStatus();
     $body = $response->getBody();
     if ($status == 200 || $status == 400 && !empty($body)) {
         return $body;
     } else {
         $this->_setError('Bad HTTP response');
         return false;
     }
 }
Example #4
0
/**
 * 构造POST和GET组合的请求 返回相应请求
 *
 * @param string $url            
 * @param array $get            
 * @param array $post            
 * @param boolean $returnObj            
 * @return Zend_Http_Response false
 */
function doRequest($url, $get = array(), $post = array(), $returnObj = false)
{
    try {
        $url = trim($url);
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
            throw new Exception('Invalid URL');
            return false;
        }
        $client = new Zend\Http\Client();
        $client->setUri($url);
        if (count($get) > 0 && is_array($get)) {
            $client->setParameterGet($get);
        }
        if (count($post) > 0 && is_array($post)) {
            $client->setParameterPost($post);
        }
        $client->setEncType(Zend\Http\Client::ENC_URLENCODED);
        $client->setOptions(array('maxredirects' => 5, 'strictredirects' => false, 'useragent' => 'Zend\\Http\\Client', 'timeout' => 10, 'adapter' => 'Zend\\Http\\Client\\Adapter\\Socket', 'httpversion' => Request::VERSION_11, 'storeresponse' => true, 'keepalive' => false, 'outputstream' => false, 'encodecookies' => true, 'argseparator' => null, 'rfc3986strict' => false));
        if (!empty($post)) {
            $client->setMethod(Request::METHOD_POST);
        } else {
            $client->setMethod(Request::METHOD_GET);
        }
        $response = $client->send();
        return $returnObj ? $response : $response->getBody();
    } catch (Exception $e) {
        fb(exceptionMsg($e), \FirePHP::LOG);
        return false;
    }
}
Example #5
0
 /**
  * @throws Exception\ReceiversWasNotSpecified
  */
 public function send()
 {
     if (!count($this->getMessages())) {
         throw new Exception\ReceiversWasNotSpecified();
     }
     $client = new \Zend\Http\Client();
     $client->setUri(implode('/', [self::getConfig()['uri'], 'index/send']));
     $client->setHeaders(['x-auth' => self::getToken()]);
     $client->setMethod('POST');
     $messages = [];
     foreach ($this->getMessages() as $message) {
         $messages[] = $message->asArray();
     }
     $client->setParameterPost(['messages' => $messages]);
     return $client->send()->getBody();
 }