Example #1
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;
     }
 }