Example #1
0
 public function post($post_data, $timeout = 5)
 {
     $cookie_file = $this->_cookie->file;
     $ch = curl_init();
     $header = $this->_header;
     $header['Content-Type'] = 'application/json';
     curl_setopt_array($ch, [CURLOPT_COOKIEJAR => $cookie_file, CURLOPT_COOKIEFILE => $cookie_file, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_URL => $this->_url, CURLOPT_AUTOREFERER => false, CURLOPT_FOLLOWLOCATION => false, CURLOPT_CONNECTTIMEOUT => $timeout, CURLOPT_TIMEOUT => $timeout, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'] ?: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)', CURLOPT_HTTPHEADER => $header]);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     \Gini\Logger::of('core')->debug('RPC => {url}: {data}', ['url' => $this->_url, 'data' => $post_data]);
     $data = curl_exec($ch);
     $errno = curl_errno($ch);
     if ($errno) {
         $message = curl_error($ch);
         curl_close($ch);
         \Gini\Logger::of('core')->error('RPC cURL error: {message}', ['message' => $message]);
         throw IoC::construct('\\Gini\\RPC\\Exception', "transport error: {$message}", -32300);
     }
     curl_close($ch);
     return $data;
 }
Example #2
0
File: HTTP.php Project: iamfat/gini
 public function enableCookie()
 {
     $this->_cookie = IoC::construct('\\Gini\\HTTP\\Cookie');
     return $this;
 }