Exemplo n.º 1
0
 public function execute()
 {
     if ($this->result != null) {
         return $this->result;
     }
     $this->ch = curl_init();
     curl_setopt($this->ch, CURLOPT_URL, $this->url);
     curl_setopt($this->ch, CURLOPT_HEADER, false);
     // HTTPS
     if (strpos($this->url, 'https://') === true) {
         curl_setopt($this->ch, CURLOPT_PORT, 443);
         curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
     }
     // POST
     if ($this->method == 'post') {
         curl_setopt($this->ch, CURLOPT_POST, true);
         curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->attributes);
     } else {
         if ($this->method == 'get') {
             curl_setopt($this->ch, CURLOPT_URL, Helper::appendParamsToUrl($this->url, $this->attributes));
         }
     }
     curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
     $this->result = curl_exec($this->ch);
     if (curl_errno($this->ch)) {
         echo curl_errno($this->ch) . ": " . curl_error($this->ch);
     }
     curl_close($this->ch);
     return $this->result;
 }