Example #1
0
 /**
  * @brief	Conexão HTTP
  * @details	Recupera um objeto de conexão HTTP para ser utilizado
  * nas chamadas às operações da API.
  * @return	HTTPConnection
  */
 public function getHTTPConnection()
 {
     $httpConnection = new HTTPConnection();
     $httpConnection->setCookieManager(new HTTPCookieManager());
     return $httpConnection;
 }
Example #2
0
 /**
  * @see HTTPRequest::open()
  */
 public function open(HTTPConnection $httpConnection)
 {
     if (function_exists('curl_init')) {
         /**
          * Fechamos uma conexão existente antes de abrir uma nova
          */
         $this->close();
         $curl = curl_init();
         /**
          * Verificamos se o recurso CURL foi criado com êxito
          */
         if (is_resource($curl)) {
             curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
             curl_setopt($curl, CURLOPT_HEADER, 1);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($curl, CURLINFO_HEADER_OUT, 1);
             if (($timeout = $httpConnection->getTimeout()) != null) {
                 curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
             }
             if (($connectionTimeout = $httpConnection->getConnectionTimeout()) != null) {
                 curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $connectionTimeout);
             }
             $headers = array();
             foreach ($this->requestHeader as $header) {
                 $headers[] = sprintf('%s: %s', $header['name'], $header['value']);
             }
             curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
             $this->curlResource = $curl;
             $this->httpConnection = $httpConnection;
             $this->openned = true;
         } else {
             throw new RuntimeException('Não foi possível iniciar cURL');
         }
     } else {
         throw new RuntimeException('Extensão cURL não está instalada.');
     }
 }