コード例 #1
0
ファイル: Curl.php プロジェクト: cbsantos/ClientAPI
 public function Send(HttpContext $context)
 {
     if (in_array($context->getMethod(), array('post', 'put'))) {
         $context->setHeaders('Content-Length: ' . strlen($context->getBody()));
     }
     curl_setopt($this->_cUrl, CURLOPT_URL, $context->getRequestURL());
     curl_setopt($this->_cUrl, CURLOPT_CUSTOMREQUEST, $context->getMethod());
     curl_setopt($this->_cUrl, CURLOPT_POSTFIELDS, $context->getBody());
     curl_setopt($this->_cUrl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($this->_cUrl, CURLOPT_HEADER, 1);
     if (substr($context->getHost(), 0, 5) == 'https') {
         curl_setopt($this->_cUrl, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($this->_cUrl, CURLOPT_SSL_VERIFYPEER, 0);
     }
     curl_setopt($this->_cUrl, CURLOPT_HTTPHEADER, $context->getHeaders());
     $raw = curl_exec($this->_cUrl);
     $result = new HttpResult();
     $pos = strpos($raw, "\r\n\r\n");
     $result->protocol = substr($raw, 0, 8);
     $result->headers = explode("\r\n", substr($raw, 0, $pos));
     $result->body = substr($raw, $pos + 4);
     $info = curl_getinfo($this->_cUrl);
     $result->statusCode = $info['http_code'];
     curl_close($this->_cUrl);
     return $result;
 }