本文整理汇总了PHP中RequestCore::set_curlopts方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestCore::set_curlopts方法的具体用法?PHP RequestCore::set_curlopts怎么用?PHP RequestCore::set_curlopts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestCore
的用法示例。
在下文中一共展示了RequestCore::set_curlopts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cache_instance_profile_credentials
/**
* Fetches and caches EC2 instance profile credentials. This is meant to be used by the constructor, and is not to
* be manually invoked.
*
* @param CacheCore $cache (Required) The a reference to the cache object that is being used to handle the caching.
* @param array $options (Required) The options that were passed into the constructor.
* @return mixed The data to be cached, or NULL.
*/
public function cache_instance_profile_credentials($cache, $options)
{
$instance_profile_url = 'http://169.254.169.254/latest/meta-data/iam/security-credentials/';
$connect_timeout = isset($options['instance_profile_timeout']) ? $options['instance_profile_timeout'] : 2;
try {
// Make a call to the EC2 Metadata Service to find the available instance profile
$request = new RequestCore($instance_profile_url);
$request->set_curlopts(array(CURLOPT_CONNECTTIMEOUT => $connect_timeout));
$response = $request->send_request(true);
if ($response->isOK()) {
// Get the instance profile name
$profile = (string) $response->body;
// Make a call to the EC2 Metadata Service to get the instance profile credentials
$request = new RequestCore($instance_profile_url . $profile);
$request->set_curlopts(array(CURLOPT_CONNECTTIMEOUT => $connect_timeout));
$response = $request->send_request(true);
if ($response->isOK()) {
// Get the credentials
$credentials = json_decode($response->body, true);
if ($credentials['Code'] === 'Success') {
// Determine the expiration time
$expiration_time = strtotime((string) $credentials['Expiration']);
$expiration_duration = round(($expiration_time - time()) * 0.85);
$cache->expire_in($expiration_duration);
// Return the credential information
return array('key' => $credentials['AccessKeyId'], 'secret' => $credentials['SecretAccessKey'], 'token' => $credentials['Token'], 'expires' => $credentials['Expiration']);
}
}
}
} catch (cURL_Exception $e) {
// The EC2 Metadata Service does not exist or had timed out.
// An exception will be thrown on the next line.
}
// @codeCoverageIgnoreStart
throw new CFCredentials_Exception('No credentials were provided. The SDK attempted to retrieve Instance ' . 'Profile credentials from the EC2 Instance Metadata Service, but failed to do so. Instance profile ' . 'credentials are only accessible on EC2 instances configured with a specific IAM role.');
// @codeCoverageIgnoreEnd
}
示例2: _baseControl
/**
* _baseControl
*
* 用户关注:否
*
* 网络交互方法
*
* @access protected
* @param array $opt 参数数组
* @throws ChannelException 如果出错,则抛出异常,错误号为self::CHANNEL_SDK_SYS
*
* @version 1.0.0.0
*/
protected function _baseControl($opt)
{
$content = '';
$resource = 'channel';
if (isset($opt[self::CHANNEL_ID]) && !is_null($opt[self::CHANNEL_ID]) && !in_array($opt[self::METHOD], $this->_method_channel_in_body)) {
$resource = $opt[self::CHANNEL_ID];
unset($opt[self::CHANNEL_ID]);
}
$host = $opt[self::HOST];
unset($opt[self::HOST]);
$url = $host . '/rest/2.0/' . self::PRODUCT . '/';
$url .= $resource;
$http_method = 'POST';
$opt[self::SIGN] = $this->_genSign($http_method, $url, $opt);
foreach ($opt as $k => $v) {
$k = urlencode($k);
$v = urlencode($v);
$content .= $k . '=' . $v . '&';
}
$content = substr($content, 0, strlen($content) - 1);
$request = new RequestCore($url);
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
$headers['User-Agent'] = 'Baidu Channel Service Phpsdk Client';
foreach ($headers as $headerKey => $headerValue) {
$headerValue = str_replace(array("\r", "\n"), '', $headerValue);
if ($headerValue !== '') {
$request->add_header($headerKey, $headerValue);
}
}
$request->set_method($http_method);
$request->set_body($content);
if (is_array($this->_curlOpts)) {
$request->set_curlopts($this->_curlOpts);
}
$request->send_request();
return new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
}
示例3: acquire_activation_code
/**
* Fetches the activation code for a gateway using its public URL.
*
* @param string $gateway_url (Required) The public URL to a gateway.
* @return string|boolean The activation key for the gateway, or false if it could not be determined.
*/
public function acquire_activation_code($gateway_url)
{
// Send a request to the gateway's URL
$request = new RequestCore($gateway_url);
$request->ssl_verification = false;
$request->set_curlopts(array(CURLOPT_FOLLOWLOCATION => false));
$response = $request->send_request(true);
// Parse the query string from the URL in the location header to get the activation key
if (isset($response->header['location'])) {
$url = $response->header['location'];
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $params);
if (isset($params['activationKey'])) {
return $params['activationKey'];
}
}
return false;
}