コード例 #1
0
 function initialize()
 {
     if (!$this->fetched) {
         $config =& get_config();
         $assetUrl = $config['asset_service'] . $this->node['AssetID'];
         $curl = new Curl();
         $curl->create($assetUrl);
         $curl->option(CURLOPT_HEADER, true);
         $curl->option(CURLOPT_NOBODY, true);
         $response = $curl->execute();
         if ($response) {
             $headers = http_parse_headers($response);
             $this->size = $headers['Content-Length'];
             $this->contentType = $headers['Content-Type'];
             if (isset($headers['ETag'])) {
                 $this->etag = $headers['ETag'];
             } else {
                 if (isset($headers['Etag'])) {
                     $this->etag = $headers['Etag'];
                 } else {
                     $this->etag = '';
                 }
             }
         } else {
             log_message('error', "InventoryFile: Failed to fetch headers from {$assetUrl}");
         }
         $this->fetched = true;
     }
 }
コード例 #2
0
 function execute($method, $url, $fields = '', $userAgent = '', $httpHeaders = '', $username = '', $password = '')
 {
     $ch = Curl::create();
     if (false === $ch) {
         return false;
     }
     if (is_string($url) && strlen($url)) {
         $ret = curl_setopt($ch, CURLOPT_URL, $url);
     } else {
         return false;
     }
     //是否显示头部信息
     curl_setopt($ch, CURLOPT_HEADER, false);
     //
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     if ($username != '') {
         curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
     }
     $method = strtolower($method);
     if ('post' == $method) {
         curl_setopt($ch, CURLOPT_POST, true);
         if (is_array($fields)) {
             $sets = array();
             foreach ($fields as $key => $val) {
                 $sets[] = $key . '=' . urlencode($val);
             }
             $fields = implode('&', $sets);
         }
         curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
     } else {
         if ('put' == $method) {
             curl_setopt($ch, CURLOPT_PUT, true);
         }
     }
     //curl_setopt($ch, CURLOPT_PROGRESS, true);
     //curl_setopt($ch, CURLOPT_VERBOSE, true);
     //curl_setopt($ch, CURLOPT_MUTE, false);
     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     //设置curl超时秒数,例如将信息POST出去3秒钟后自动结束运行。
     if (strlen($userAgent)) {
         curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
     }
     if (is_array($httpHeaders)) {
         curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
     }
     $ret = curl_exec($ch);
     if (curl_errno($ch)) {
         curl_close($ch);
         return array(curl_error($ch), curl_errno($ch));
     } else {
         curl_close($ch);
         if (!is_string($ret) || !strlen($ret)) {
             return false;
         }
         return $ret;
     }
 }
コード例 #3
0
function create_asset($assetID, $creatorID, $contentType, $filename)
{
    $CI =& get_instance();
    $CI->load->library('Curl');
    $CI->load->helper('path');
    $filename = rtrim(set_realpath($filename), '/');
    $params = array('AssetID' => $assetID, 'CreatorID' => $creatorID, 'Asset' => "@{$filename};type={$contentType}");
    echo 'Posting ' . $filename . ' to ' . $CI->config->item('asset_service') . '<br/>';
    $curl = new Curl();
    $curl->create($CI->config->item('asset_service'));
    $curl->option(CURLOPT_POST, TRUE);
    $curl->option(CURLOPT_POSTFIELDS, $params);
    $curl->http_method('post');
    $response = json_decode($curl->execute(), TRUE);
    if (!isset($response)) {
        $response = array('Message' => 'Invalid or missing response. ' . $curl->error_string);
    }
    return $response;
}
コード例 #4
0
ファイル: Cloud.class.php プロジェクト: sandom123/king400
 /**
  * 请求
  * @param type $data
  * @return type
  */
 private function run($data)
 {
     $curl = new \Curl();
     $fields = array('data' => json_encode($data), 'version' => SHUIPF_VERSION, 'act' => $this->act, 'identity' => $this->getIdentity(), 'token' => $this->token);
     //curl支持 检测
     if ($curl->create() == false) {
         $this->error = '服务器不支持Curl扩展!';
         return false;
     }
     //请求
     $status = $curl->post(self::serverHot, $fields);
     if (false == $status) {
         $this->error = '无法联系服务器,请稍后再试!';
         return false;
     }
     return $this->returnResolve($status);
 }
コード例 #5
0
ファイル: index.php プロジェクト: ronfesta/simiangrid
 $sql = "SELECT Resource FROM Capabilities WHERE ID=:ID AND ExpirationDate > NOW() LIMIT 1";
 $sth = $db->prepare($sql);
 if ($sth->execute(array(':ID' => $_GET['cap']))) {
     if ($sth->rowCount() > 0) {
         $obj = $sth->fetchObject();
         $resourceURL = $obj->Resource;
         // TODO: Handle relative resource URLs
         if (stripos($_SERVER['REQUEST_METHOD'], 'POST') !== FALSE) {
             // FIXME: Implement POST capability routing
             $curl = new Curl();
             $curl->create($resourceURL);
         } else {
             if (stripos($_SERVER['REQUEST_METHOD'], 'GET') !== FALSE) {
                 // FIXME: Properly proxy response codes
                 $curl = new Curl();
                 $curl->create($resourceURL);
                 echo $curl->execute();
                 exit;
             } else {
                 log_message('warn', "Don't know how to route method " . $_SERVER['REQUEST_METHOD'] . " for capability {$resourceURL}");
                 header("HTTP/1.1 400 Bad Request");
                 echo 'Request method not understood';
                 exit;
             }
         }
     } else {
         log_message('warn', "Capability " . $_GET['cap'] . " not found");
         header("HTTP/1.1 404 Not Found");
         echo 'Capability not found';
         exit;
     }