本文整理汇总了PHP中Curl::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Curl::create方法的具体用法?PHP Curl::create怎么用?PHP Curl::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Curl
的用法示例。
在下文中一共展示了Curl::create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
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: execute
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: create_asset
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: run
/**
* 请求
* @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: NOW
$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;
}