Example #1
0
 /**
  * @return $this
  * @throws HttpException
  * @codeCoverageIgnore
  */
 public function send()
 {
     $ch = curl_init();
     $response = null;
     try {
         curl_setopt($ch, CURLOPT_URL, $this->getUrlWithQueryString());
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->getMethod());
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, true);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeadersArray());
         if ($this->isPut() || $this->isPost()) {
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $this->getEncodedBody());
         }
         $res = curl_exec($ch);
         $response = new Response(curl_getinfo($ch, CURLINFO_HTTP_CODE), $res);
         if (!$response->checkStatus()) {
             throw new Exception('Response has unsuccessful status');
         }
     } catch (Exception $e) {
         curl_close($ch);
         throw new HttpException($this, $response, $e);
     }
     curl_close($ch);
     return $response;
 }