当前位置: 首页>>代码示例>>PHP>>正文


PHP RequestCore::send_request方法代码示例

本文整理汇总了PHP中RequestCore::send_request方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestCore::send_request方法的具体用法?PHP RequestCore::send_request怎么用?PHP RequestCore::send_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RequestCore的用法示例。


在下文中一共展示了RequestCore::send_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upload

/**
 *	upload()
 *
 *	Processes uploaded backup file.
 *
 *	@return		array		True on upload success; false otherwise.
 */
function upload()
{
    if (isset($_POST['upload']) && $_POST['upload'] == 'local') {
        if (pb_backupbuddy::$options['password'] != '#PASSWORD#') {
            $path_parts = pathinfo($_FILES['file']['name']);
            if (strtolower(substr($_FILES['file']['name'], 0, 6)) == 'backup' && strtolower($path_parts['extension']) == 'zip') {
                if (move_uploaded_file($_FILES['file']['tmp_name'], basename($_FILES['file']['name']))) {
                    pb_backupbuddy::alert('File Uploaded. Your backup was successfully uploaded.');
                    return true;
                } else {
                    pb_backupbuddy::alert('Sorry, there was a problem uploading your file.', true);
                    return false;
                }
            } else {
                pb_backupbuddy::alert('Only properly named BackupBuddy zip archives with a zip extension may be uploaded.', true);
                return false;
            }
        } else {
            pb_backupbuddy::alert('Upload Access Denied. To prevent unauthorized file uploads an importbuddy password must be configured and properly entered to use this feature.');
            return false;
        }
    }
    // DOWNLOAD FILE FROM STASH TO LOCAL.
    if (pb_backupbuddy::_POST('upload') == 'stash') {
        pb_backupbuddy::set_greedy_script_limits(true);
        /*
        echo '<pre>';
        print_r( $_POST );
        echo '</pre>';
        */
        $requestcore_file = dirname(dirname(dirname(__FILE__))) . '/lib/requestcore/requestcore.class.php';
        require_once $requestcore_file;
        $link = pb_backupbuddy::_POST('link');
        $destination_file = dirname(dirname(dirname(dirname(__FILE__)))) . '/' . basename(pb_backupbuddy::_POST('link'));
        $destination_file = substr($destination_file, 0, stripos($destination_file, '.zip') + 4);
        $_GET['file'] = basename($destination_file);
        $request = new RequestCore($link);
        $request->set_write_file($destination_file);
        echo '<div id="pb_importbuddy_working" style="padding: 20px;">Downloading backup from Stash to `' . $destination_file . '`...<br><br><img src="' . pb_backupbuddy::plugin_url() . '/images/loading_large.gif" title="Working... Please wait as this may take a moment..."><br><br></div>';
        flush();
        $response = $request->send_request(false);
        if ($response !== true) {
            pb_backupbuddy::alert('Error #8548459598. Unable to download file from Stash. You may manually download it and upload to the server via FTP.');
        } else {
            // No error.
            if (!file_exists($destination_file)) {
                pb_backupbuddy::alert('Error #34845745878. Stash returned a success but the backup file was not found locally. Check this server\'s directory write permissions. You may manually download it and upload to the server via FTP.');
            }
        }
        echo '<script type="text/javascript">jQuery("#pb_importbuddy_working").hide();</script>';
    }
}
开发者ID:brettex,项目名称:pspark,代码行数:59,代码来源:1.php

示例2: sign_url_for_put

function sign_url_for_put($obj)
{
    global $bucket;
    global $object;
    $timeout = 3600;
    //通过content上传
    $options = NULL;
    $response = $obj->presign_url($bucket, $object, $timeout, "PUT", $options);
    SampleUtil::my_echo("签名的URL为:" . $response);
    $content = 'abcdefg';
    $request = new RequestCore($response);
    $request->set_method('PUT');
    $request->add_header('Content-Type', '');
    $request->add_header('Content-Length', strlen($content));
    $request->set_body($content);
    $request->send_request();
    $res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
    if ($res->isOK()) {
        SampleUtil::my_echo("签名上传字符串成功");
    } else {
        SampleUtil::my_echo("签名上传字符串失败");
    }
    //通过file上传
    $file = __FILE__;
    if (!file_exists($file)) {
        throw new OSS_Exception($file . OSS_FILE_NOT_EXIST);
    }
    $options = array('Content-Type' => 'txt');
    $response = $obj->presign_url($bucket, $object, $timeout, "PUT", $options);
    SampleUtil::my_echo("签名的URL为:" . $response);
    $request = new RequestCore($response);
    $request->set_method('PUT');
    $request->add_header('Content-Type', 'txt');
    $request->set_read_file($file);
    $request->set_read_stream_size(filesize($file));
    $request->send_request();
    $res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
    if ($res->isOK()) {
        SampleUtil::my_echo("签名上传文件成功");
    } else {
        SampleUtil::my_echo("签名上传字符串失败");
    }
}
开发者ID:codingoneapp,项目名称:codingone,代码行数:43,代码来源:signature_sample.php

示例3: _baseControl

 /**
  * 调用API
  * @param string $apiMethod api方法名
  * @param array || string  $params 请求参数
  * @param string $method HTTP请求类型
  * @param string $headers 附加的HTTP HEADER信息
  * @return string
  */
 private function _baseControl($apiMethod, $params, $method = 'GET', $headers = array())
 {
     $method = strtoupper($method);
     if (is_array($params)) {
         $params = http_build_query($params, '', '&');
     }
     $url = $this->_pcs_uri_prefixs['https'] . $apiMethod . ($method == 'GET' ? '&' . $params : '');
     $requestCore = new RequestCore();
     $requestCore->set_request_url($url);
     $requestCore->set_method($method);
     if ($method == 'POST') {
         $requestCore->set_body($params);
     }
     foreach ($headers as $key => $value) {
         $requestCore->add_header($key, $value);
     }
     $requestCore->send_request();
     $result = $requestCore->get_response_body();
     return $result;
 }
开发者ID:hsiun,项目名称:doudo,代码行数:28,代码来源:BaiduPCS.class.php

示例4: get_manage_data

 public static function get_manage_data($settings, $suppressAuthAlert = false)
 {
     $itxapi_username = $settings['itxapi_username'];
     $itxapi_password = $settings['itxapi_password'];
     require_once dirname(__FILE__) . '/lib/class.itx_helper.php';
     require_once dirname(dirname(__FILE__)) . '/_s3lib/aws-sdk/sdk.class.php';
     $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
     //  get the url to use to request management credentials
     //  url looks something like this - http://api.ithemes.com/stash/upload?apikey=sb31kesem0c879m0&expires=1347439653&subscriber=jwooley&signature=VFMbmXb5OorWwqE0iedOCsDtSgs%3D
     $manage_url = $stash->get_manage_url();
     //  create a new RequestCore to get the credentials
     //  NOTE: RequestCore is part of the AWS SDK, it's a generic http request class.
     //        You can use any available function to make the api request, the wordpress http class for example,
     //        or even just the basic file_get_contents()
     $request = new RequestCore($manage_url);
     //  send the api request
     try {
         $response = $request->send_request(true);
     } catch (Exception $e) {
         $error = 'Error #23873631: Unable to initiate Stash request. Details:`' . $e->getMessage() . '`.';
         pb_backupbuddy::status('error', $error);
         echo $error;
         return false;
     }
     //  see if the request was successful
     if (!$response->isOK()) {
         //throw new Exception('Request for management credentials failed.');
         $error = 'Request for management credentials failed.';
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     //  see if we got a json response
     if (!($manage_data = json_decode($response->body, true))) {
         $error = 'Did not get valid JSON response.';
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     //  finally see if the API returned an error
     if (isset($manage_data['error'])) {
         $error = 'Error: ' . implode(' - ', $manage_data['error']);
         pb_backupbuddy::status('error', $error);
         if (true === $suppressAuthAlert && '3002' == $manage_data['error']['code']) {
             // Alert suppressed.
         } else {
             pb_backupbuddy::alert($error);
         }
         return false;
     }
     if ('1' == $settings['use_packaged_cert']) {
         pb_backupbuddy::status('details', 'Using packaged cacert.pem file based on destination settings.');
         $manage_data['ssl.certificate_authority'] = pb_backupbuddy::plugin_path() . '/destinations/_s3lib/aws-sdk/lib/requestcore/cacert.pem';
     }
     return $manage_data;
 }
开发者ID:Offirmo,项目名称:base-wordpress,代码行数:56,代码来源:init.php

示例5: invoke


//.........这里部分代码省略.........
                 $index = explode("->", $position);
                 $curIndexArg = $args;
                 $add = TRUE;
                 $curkey = "";
                 foreach ($index as $key1 => $value1) {
                     if (!isset($curIndexArg[$value1])) {
                         $add = FALSE;
                     } else {
                         $curIndexArg = $curIndexArg[$value1];
                         $curkey = $value1;
                     }
                 }
                 if (!empty($curIndexArg) && $add) {
                     $request->body = $curIndexArg;
                 }
             }
         }
     }
     //add ext headers
     //TODO
     //sign request
     $signer = NULL;
     if (isset($api["signer"])) {
         $signers = explode("->", $api["signer"]);
         foreach ($signers as $key => $value) {
             $signer = new $value();
             $log = $signer->sign($request, array("accessKey" => $this->accessKey, "secretKey" => $this->secretKey, "args" => $args));
             if (!empty($log)) {
                 $holder->msg .= $log . "\r\n";
             }
         }
     }
     if ($signer === NULL || !$signer instanceof QueryAuthSigner) {
         $url = $request->toUrl($this->endpoint);
         if ($location != NULL) {
             $url = $location;
         }
         $httpRequest = new RequestCore($url);
         if (KS3_API_DEBUG_MODE === TRUE) {
             $httpRequest->debug_mode = TRUE;
         }
         $httpRequest->set_method($request->method);
         foreach ($request->headers as $key => $value) {
             $httpRequest->add_header($key, $value);
         }
         $httpRequest->request_body = $request->body;
         if (isset($args["writeCallBack"])) {
             $httpRequest->register_streaming_write_callback($args["writeCallBack"]);
         }
         if (isset($args["readCallBack"])) {
             $httpRequest->register_streaming_read_callback($args["readCallBack"]);
         }
         $read_stream = $request->read_stream;
         $read_length = $request->getHeader(Headers::$ContentLength);
         $seek_position = $request->seek_position;
         if (isset($read_stream)) {
             $httpRequest->set_read_stream($read_stream, $read_length);
             $httpRequest->set_seek_position($seek_position);
             $httpRequest->remove_header(Headers::$ContentLength);
         }
         $write_stream = $request->write_stream;
         if (isset($write_stream)) {
             $httpRequest->set_write_stream($write_stream);
         }
         $holder->msg .= "request url->" . serialize($httpRequest->request_url) . "\r\n";
         $holder->msg .= "request headers->" . serialize($httpRequest->request_headers) . "\r\n";
         $holder->msg .= "request body->" . $httpRequest->request_body . "\r\n";
         $holder->msg .= "request read stream length->" . $read_length . "\r\n";
         $holder->msg .= "request read stream seek position->" . $seek_position . "\r\n";
         $httpRequest->send_request();
         //print_r($httpRequest);
         $body = $httpRequest->get_response_body();
         $data = new ResponseCore($httpRequest->get_response_header(), Utils::replaceNS2($body), $httpRequest->get_response_code());
         if ($data->status == 307) {
             $respHeaders = $httpRequest->get_response_header();
             $location = $respHeaders["location"];
             if (substr($location, 0, 4) == "http") {
                 $holder->msg .= "response code->" . $httpRequest->get_response_code() . "\r\n";
                 $holder->msg .= "response headers->" . serialize($httpRequest->get_response_header()) . "\r\n";
                 $holder->msg .= "response body->" . $body . "\r\n";
                 $holder->msg .= "retry request to " . $location . "\r\n";
                 //array($args)详见invoke开头
                 return $this->invoke($method, array($args), $holder, $location);
             }
         }
         $holder->msg .= "response code->" . $httpRequest->get_response_code() . "\r\n";
         $holder->msg .= "response headers->" . serialize($httpRequest->get_response_header()) . "\r\n";
         $holder->msg .= "response body->" . $body . "\r\n";
         $handlers = explode("->", $api["handler"]);
         foreach ($handlers as $key => $value) {
             $handler = new $value();
             $data = $handler->handle($data);
         }
         return $data;
     } else {
         $url = $request->toUrl($this->endpoint);
         $holder->msg .= $url . "\r\n";
         return $url;
     }
 }
开发者ID:zengdongbao,项目名称:ks3-php,代码行数:101,代码来源:Ks3Client.class.php

示例6: dirname

     echo $login_welcome;
     pb_backupbuddy::alert(implode('<br>', $settings_result['errors']));
     $credentials_form->display_settings('Connect to Stash');
 } else {
     // No form errors; process!
     $itx_helper_file = dirname(dirname(__FILE__)) . '/classes/class.itx_helper.php';
     require_once $itx_helper_file;
     $itxapi_username = $settings_result['data']['itxapi_username'];
     $itxapi_password = ITXAPI_Helper::get_password_hash($itxapi_username, $settings_result['data']['itxapi_password_raw']);
     // Generates hash for use as password for API.
     $requestcore_file = dirname(dirname(__FILE__)) . '/lib/requestcore/requestcore.class.php';
     require_once $requestcore_file;
     $stash = new ITXAPI_Helper($ITXAPI_KEY, $ITXAPI_URL, $itxapi_username, $itxapi_password);
     $files_url = $stash->get_files_url();
     $request = new RequestCore($files_url);
     $response = $request->send_request(true);
     // See if the request was successful.
     if (!$response->isOK()) {
         pb_backupbuddy::status('error', 'Stash request for files failed.');
     }
     // See if we got a json response.
     if (!($stash_files = json_decode($response->body, true))) {
         pb_backupbuddy::status('error', 'Stash did not get valid json response.');
     }
     // Finally see if the API returned an error.
     if (isset($stash_files['error'])) {
         if ($stash_files['error']['code'] == '3002') {
             pb_backupbuddy::alert('Invalid iThemes.com Member account password. Please verify your password. <a href="http://ithemes.com/member/member.php" target="_new">Forget your password?</a>');
         } else {
             pb_backupbuddy::alert(implode(' - ', $stash_files['error']));
         }
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:31,代码来源:_html_1_stash.php

示例7: testPutObjectAclPresignedUrl

 public function testPutObjectAclPresignedUrl()
 {
     $this->testPutObjectPresignedUrl();
     $url = $this->client->generatePresignedUrl(array("Method" => "PUT", "Bucket" => $this->bucket, "Key" => $this->key, "Options" => array("Expires" => 60 * 10, "acl" => NULL), "Headers" => array("Content-Type" => "text/plain", "x-kss-acl" => "public-read")));
     $httpRequest = new RequestCore($url);
     $httpRequest->set_method("PUT");
     $httpRequest->add_header("Content-Type", "text/plain");
     $httpRequest->add_header("x-kss-acl", "public-read");
     $httpRequest->send_request();
     $body = $httpRequest->get_response_body();
     $this->assertEquals($httpRequest->get_response_code() . " body:" . $body, 200, "put object acl status code");
 }
开发者ID:leunico,项目名称:aliceBlog,代码行数:12,代码来源:Test.php

示例8: getHttpResponse

 /**
  * @return array
  */
 protected function getHttpResponse($method, $url, $body, $headers)
 {
     $request = new RequestCore($url);
     foreach ($headers as $key => $value) {
         $request->add_header($key, $value);
     }
     $request->set_method($method);
     $request->set_useragent(USER_AGENT);
     if ($method == "POST") {
         $request->set_body($body);
     }
     $request->send_request();
     $response = array();
     $response[] = (int) $request->get_response_code();
     $response[] = $request->get_response_header();
     $response[] = $request->get_response_body();
     return $response;
 }
开发者ID:jesse108,项目名称:admin_base,代码行数:21,代码来源:Client.php

示例9: basename

 function process_remote_copy($destination_type, $file, $settings)
 {
     pb_backupbuddy::status('details', 'Copying remote `' . $destination_type . '` file `' . $file . '` down to local.');
     pb_backupbuddy::set_greedy_script_limits();
     if (!class_exists('backupbuddy_core')) {
         require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
     }
     // Determine destination filename.
     $destination_file = backupbuddy_core::getBackupDirectory() . basename($file);
     if (file_exists($destination_file)) {
         $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
     }
     pb_backupbuddy::status('details', 'Filename of resulting local copy: `' . $destination_file . '`.');
     if ($destination_type == 'stash2') {
         require_once ABSPATH . 'wp-admin/includes/file.php';
         pb_backupbuddy::status('details', 'About to begin downloading from URL.');
         $download = download_url($url);
         pb_backupbuddy::status('details', 'Download process complete.');
         if (is_wp_error($download)) {
             $error = 'Error #832989323: Unable to download file `' . $file . '` from URL: `' . $url . '`. Details: `' . $download->get_error_message() . '`.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         } else {
             if (false === copy($download, $destination_file)) {
                 $error = 'Error #3329383: Unable to copy file from `' . $download . '` to `' . $destination_file . '`.';
                 pb_backupbuddy::status('error', $error);
                 pb_backupbuddy::alert($error);
                 @unlink($download);
                 return false;
             } else {
                 pb_backupbuddy::status('details', 'File saved to `' . $destination_file . '`.');
                 @unlink($download);
                 return true;
             }
         }
     }
     // end stash2.
     if ($destination_type == 'stash') {
         $itxapi_username = $settings['itxapi_username'];
         $itxapi_password = $settings['itxapi_password'];
         // Load required files.
         pb_backupbuddy::status('details', 'Load Stash files.');
         require_once pb_backupbuddy::plugin_path() . '/destinations/stash/init.php';
         require_once dirname(dirname(__FILE__)) . '/destinations/_s3lib/aws-sdk/sdk.class.php';
         require_once pb_backupbuddy::plugin_path() . '/destinations/stash/lib/class.itx_helper.php';
         // Talk with the Stash API to get access to do things.
         pb_backupbuddy::status('details', 'Authenticating Stash for remote copy to local.');
         $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
         $manage_url = $stash->get_manage_url();
         $request = new RequestCore($manage_url);
         $response = $request->send_request(true);
         // Validate response.
         if (!$response->isOK()) {
             $error = 'Request for management credentials failed.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         if (!($manage_data = json_decode($response->body, true))) {
             $error = 'Did not get valid JSON response.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         if (isset($manage_data['error'])) {
             $error = 'Error: ' . implode(' - ', $manage_data['error']);
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         // Connect to S3.
         pb_backupbuddy::status('details', 'Instantiating S3 object.');
         $s3 = new AmazonS3($manage_data['credentials']);
         pb_backupbuddy::status('details', 'About to get Stash object `' . $file . '`...');
         try {
             $response = $s3->get_object($manage_data['bucket'], $manage_data['subkey'] . pb_backupbuddy_destination_stash::get_remote_path() . $file, array('fileDownload' => $destination_file));
         } catch (Exception $e) {
             pb_backupbuddy::status('error', 'Error #5443984: ' . $e->getMessage());
             error_log('err:' . $e->getMessage());
             return false;
         }
         if ($response->isOK()) {
             pb_backupbuddy::status('details', 'Stash copy to local success.');
             return true;
         } else {
             pb_backupbuddy::status('error', 'Error #894597845. Stash copy to local FAILURE. Details: `' . print_r($response, true) . '`.');
             return false;
         }
     } elseif ($destination_type == 'gdrive') {
         die('Not implemented here.');
         require_once pb_backupbuddy::plugin_path() . '/destinations/gdrive/init.php';
         $settings = array_merge(pb_backupbuddy_destination_gdrive::$default_settings, $settings);
         if (true === pb_backupbuddy_destination_gdrive::getFile($settings, $file, $destination_file)) {
             // success
             pb_backupbuddy::status('details', 'Google Drive copy to local success.');
             return true;
         } else {
             // fail
             pb_backupbuddy::status('details', 'Error #2332903. Google Drive copy to local FAILURE.');
//.........这里部分代码省略.........
开发者ID:elephantcode,项目名称:elephantcode,代码行数:101,代码来源:cron.php

示例10: 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
 }
开发者ID:platonicsolution,项目名称:local-server,代码行数:45,代码来源:sdk.class.php

示例11: create_db

 public static function create_db($cpanel_user, $cpanel_password, $cpanel_host, $db_name, $db_user, $db_userpass, $cpanel_port = '2082')
 {
     $cpanel_skin = "x3";
     $errors = array();
     $cpanel_password = urlencode($cpanel_password);
     // Pass often has special chars so encode.
     // Calculate base URL.
     // 		$base_url = "http://{$cpanel_user}:{$cpanel_password}@{$cpanel_host}:{$cpanel_port}/frontend/{$cpanel_skin}";
     $base_url = "http://{$cpanel_user}:{$cpanel_password}@{$cpanel_host}:{$cpanel_port}/execute/Mysql";
     // Generate create database URL.
     // 		$create_database_url = $base_url . "/sql/addb.html?db={$db_name}";
     $create_database_url = $base_url . "/create_database?name={$cpanel_user}_{$db_name}";
     //echo $create_database_url . '<br>';
     // Create request core obj for connecting to HTTP.
     $request = new RequestCore($create_database_url);
     try {
         $result = $request->send_request(true);
     } catch (Exception $e) {
         if (stristr($e->getMessage(), 'couldn\'t connect to host') !== false) {
             $errors[] = 'Unable to connect to host `' . $cpanel_host . '` on port `' . $cpanel_port . '`. Verify the cPanel domain/URL and make sure the server is able to initiate outgoing http connections on port ' . $cpanel_port . '. Some hosts block this.';
             return $errors;
         }
         $errors[] = 'Caught exception: ' . $e->getMessage();
         return $errors;
     }
     // Generate create database user URL.
     // 		$create_user_url = $base_url . "/sql/adduser.html?user={$db_user}&pass={$db_userpass}";
     $create_user_url = $base_url . "/create_user?name={$cpanel_user}_{$db_user}&password={$db_userpass}";
     //echo $create_user_url . '<br>';
     // Generate assign user database access URL.
     // 		$assign_user_url = $base_url . "/sql/addusertodb.html?user={$cpanel_user}_{$db_user}&db={$cpanel_user}_{$db_name}&ALL=ALL";
     $assign_user_url = $base_url . "/set_privileges_on_database?user={$cpanel_user}_{$db_user}&database={$cpanel_user}_{$db_name}&privileges=ALL";
     //echo $assign_user_url . '<br>';
     if (false === $result->isOK()) {
         $errors[] = 'Unable to create database - response status code: ' . $result->status;
     } else {
         $result_array = json_decode($result->body, true);
         if (isset($result_array['status']) && 0 == $result_array['status']) {
             // status = 0 means a failure
             $errors[] = 'Unable to create database:';
             if (isset($result_array['errors']) && is_array($result_array['errors'])) {
                 foreach ($result_array['errors'] as $error) {
                     $errors[] = $error;
                 }
             }
         }
     }
     // 		if ( stristr( $result, 'Log in' ) !== false ) { // No sucess adding DB.
     // 			$errors[] = 'Unable to log into cPanel with given username/password. Verify the credentials are correct for this cPanel domain.';
     // 		}
     // 		if ( stristr( $result, 'Added the Database' ) === false ) { // No sucess adding DB.
     // 			$errors[] = 'Error encountered adding database.';
     // 		}
     // 		if ( stristr( $result, 'problem creating the database' ) !== false ) { // Something failed.
     // 			$errors[] = 'Unable to create database.';
     // 		}
     // 		if ( stristr( $result, 'database name already exists' ) !== false ) { // DB already exists.
     // 			$errors[] = 'The database name already exists.';
     // 		}
     // Run create database user.
     if (count($errors) === 0) {
         $request = new RequestCore($create_user_url);
         try {
             $result = $request->send_request(true);
         } catch (Exception $e) {
             $errors[] = 'Caught exception: ' . $e->getMessage();
             return $errors;
         }
         if (false === $result->isOK()) {
             $errors[] = 'Unable to creaet user - response status code: ' . $result->status;
         } else {
             $result_array = json_decode($result->body, true);
             if (isset($result_array['status']) && 0 == $result_array['status']) {
                 // status = 0 means a failure
                 $errors[] = 'Unable to create user:';
                 if (isset($result_array['errors']) && is_array($result_array['errors'])) {
                     foreach ($result_array['errors'] as $error) {
                         $errors[] = $error;
                     }
                 }
             }
         }
         // 			if ( stristr( $result, 'Added user' ) === false ) { // No success adding user.
         // 				$errors[] = 'Error encountered adding user.';
         // 			}
         // 			if ( stristr( $result, 'You have successfully created a MySQL user' ) === false ) { // No success adding user.
         // 				$errors[] = 'Error encountered adding user.';
         // 			}
         // 			if ( stristr( $result, 'No password given' ) !== false ) { // Already exists.
         // 				$errors[] = 'No password given.';
         // 			}
         // 			if ( stristr( $result, 'exists in the database' ) !== false ) { // Already exists.
         // 				$errors[] = 'Username already exists.';
         // 			}
     }
     // Run assign user to database.
     if (count($errors) === 0) {
         $request = new RequestCore($assign_user_url);
         try {
             $result = $request->send_request(true);
//.........这里部分代码省略.........
开发者ID:elephantcode,项目名称:elephantcode,代码行数:101,代码来源:cpanel.php

示例12: request

 /**
  * Method: request()
  * 	Requests the data, parses it, and returns it. Requires RequestCore and SimpleXML.
  *
  * Parameters:
  * 	url - _string_ (Required) The web service URL to request.
  *
  * Returns:
  * 	ResponseCore object
  */
 public function request($url)
 {
     if ($this->test_mode) {
         return $url;
     }
     // Generate cache filename
     $cache = $this->cache_path . get_class() . '_' . md5($url) . '.cache';
     // If cache exists, and is still valid, load it
     if ($this->cache_mode && file_exists($cache) && time() - filemtime($cache) < $this->cache_ttl) {
         $response = (object) json_decode(file_get_contents($cache));
         $response->_cached = true;
         // Add notice that this is a cached file
         return $response;
     }
     if (!class_exists('RequestCore')) {
         throw new Exception('This class requires RequestCore. http://requestcore.googlecode.com');
     }
     $http = new RequestCore($url);
     $http->set_useragent(LASTFM_USERAGENT);
     $http->send_request();
     $response = (object) $this->parse_response($http->get_response_body());
     if ($this->header_mode) {
         $response->_header = $http->get_response_header();
     }
     // Cache only successfuly requests
     if ($this->cache_mode && !isset($response->error)) {
         file_put_contents($cache . '_tmp', json_encode($response));
         rename($cache . '_tmp', $cache);
     }
     return $response;
 }
开发者ID:MusicalAPP,项目名称:lastfm,代码行数:41,代码来源:lastfmcache.class.php

示例13: authenticate

 /**
  * Authenticates a connection to cdnzz. Do not use directly unless implementing custom methods for
  * this class.
  *
  * @param array $options The options of the sdk request.
  * @return ResponseCore
  */
 public function authenticate($options = array())
 {
     if (!isset($options[self::CDNZZ_URL_USER])) {
         $options[self::CDNZZ_URL_USER] = $this->_username;
     }
     if (!isset($options[self::CDNZZ_URL_SIGNATURE])) {
         $options[self::CDNZZ_URL_SIGNATURE] = $this->_signature;
     }
     $scheme = $this->use_ssl ? 'https://' : 'http://';
     $hostname = $this->hostname;
     $headers = array(self::CDNZZ_HOST => $hostname, self::CDNZZ_CONTENT_TYPE => 'application/x-www-form-urlencoded', self::CDNZZ_DATE => gmdate('D, d M Y H:i:s \\G\\M\\T'));
     if (isset($options['url_path'])) {
         $path = $options['url_path'];
     }
     $request_url = $scheme . $hostname . $path;
     $request = new RequestCore($request_url);
     //$request->debug_mode=true;
     if (isset($options['api_method'])) {
         $request->set_method($options['api_method']);
     }
     $request_content = self::CDNZZ_URL_USER . '=' . $options[self::CDNZZ_URL_USER] . '&' . self::CDNZZ_URL_SIGNATURE . '=' . $options[self::CDNZZ_URL_SIGNATURE];
     if (isset($options['content'])) {
         foreach ($options['content'] as $content_key => $content_value) {
             $request_content .= '&' . $content_key . '=' . urlencode($content_value);
         }
     }
     $request->set_body($request_content);
     $headers[self::CDNZZ_CONTENT_LENGTH] = strlen($request_content);
     foreach ($headers as $header_key => $header_value) {
         $header_value = str_replace(array("\r", "\n"), '', $header_value);
         $request->add_header($header_key, $header_value);
     }
     $request->send_request();
     $response_header = $request->get_response_header();
     $response_body = $request->get_response_body();
     $data = new ResponseCore($response_header, $request->get_response_body(), $request->get_response_code());
     return $data;
 }
开发者ID:jefurry,项目名称:grid-sdk-php,代码行数:45,代码来源:cdnzzv1.sdk.class.php

示例14: request

 /**
  * Method: request()
  * 	Requests the data, parses it, and returns it. Requires RequestCore and SimpleXML.
  *
  * Parameters:
  * 	url - _string_ (Required) The web service URL to request.
  *
  * Returns:
  * 	ResponseCore object
  */
 public function request($url)
 {
     if (!$this->test_mode) {
         if (class_exists('RequestCore')) {
             $http = new RequestCore($url);
             $http->set_useragent(LASTFM_USERAGENT);
             $http->send_request();
             $response = new stdClass();
             $response->header = $http->get_response_header();
             $response->body = $this->parse_response($http->get_response_body());
             $response->status = $http->get_response_code();
             return $response;
         }
         throw new Exception('This class requires RequestCore. http://github.com/skyzyx/requestcore.');
     }
     return $url;
 }
开发者ID:MusicalAPP,项目名称:lastfm,代码行数:27,代码来源:lastfm.class.php

示例15: auth


//.........这里部分代码省略.........
     $request->set_useragent($user_agent);
     // Streaming uploads
     if (isset($options[self::OSS_FILE_UPLOAD])) {
         if (is_resource($options[self::OSS_FILE_UPLOAD])) {
             $length = null;
             if (isset($options[self::OSS_CONTENT_LENGTH])) {
                 $length = $options[self::OSS_CONTENT_LENGTH];
             } elseif (isset($options[self::OSS_SEEK_TO])) {
                 $stats = fstat($options[self::OSS_FILE_UPLOAD]);
                 if ($stats && $stats[self::OSS_SIZE] >= 0) {
                     $length = $stats[self::OSS_SIZE] - (int) $options[self::OSS_SEEK_TO];
                 }
             }
             $request->set_read_stream($options[self::OSS_FILE_UPLOAD], $length);
             if ($headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
                 $headers[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
             }
         } else {
             $request->set_read_file($options[self::OSS_FILE_UPLOAD]);
             $length = $request->read_stream_size;
             if (isset($options[self::OSS_CONTENT_LENGTH])) {
                 $length = $options[self::OSS_CONTENT_LENGTH];
             } elseif (isset($options[self::OSS_SEEK_TO]) && isset($length)) {
                 $length -= (int) $options[self::OSS_SEEK_TO];
             }
             $request->set_read_stream_size($length);
             if (isset($headers[self::OSS_CONTENT_TYPE]) && $headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
                 $mime_type = self::get_mime_type($options[self::OSS_FILE_UPLOAD]);
                 $headers[self::OSS_CONTENT_TYPE] = $mime_type;
             }
         }
     }
     if (isset($options[self::OSS_SEEK_TO])) {
         $request->set_seek_position((int) $options[self::OSS_SEEK_TO]);
     }
     if (isset($options[self::OSS_FILE_DOWNLOAD])) {
         if (is_resource($options[self::OSS_FILE_DOWNLOAD])) {
             $request->set_write_stream($options[self::OSS_FILE_DOWNLOAD]);
         } else {
             $request->set_write_file($options[self::OSS_FILE_DOWNLOAD]);
         }
     }
     if (isset($options[self::OSS_METHOD])) {
         $request->set_method($options[self::OSS_METHOD]);
         $string_to_sign .= $options[self::OSS_METHOD] . "\n";
     }
     if (isset($options[self::OSS_CONTENT])) {
         $request->set_body($options[self::OSS_CONTENT]);
         if ($headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
             $headers[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
         }
         $headers[self::OSS_CONTENT_LENGTH] = strlen($options[self::OSS_CONTENT]);
         $headers[self::OSS_CONTENT_MD5] = base64_encode(md5($options[self::OSS_CONTENT], true));
     }
     uksort($headers, 'strnatcasecmp');
     foreach ($headers as $header_key => $header_value) {
         $header_value = str_replace(array("\r", "\n"), '', $header_value);
         if ($header_value !== '') {
             $request->add_header($header_key, $header_value);
         }
         if (strtolower($header_key) === 'content-md5' || strtolower($header_key) === 'content-type' || strtolower($header_key) === 'date' || isset($options['self::OSS_PREAUTH']) && (int) $options['self::OSS_PREAUTH'] > 0) {
             $string_to_sign .= $header_value . "\n";
         } elseif (substr(strtolower($header_key), 0, 6) === self::OSS_DEFAULT_PREFIX) {
             $string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n";
         }
     }
     $string_to_sign .= '/' . $options[self::OSS_BUCKET];
     $string_to_sign .= $this->enable_domain_style ? $options[self::OSS_BUCKET] != '' ? $options[self::OSS_OBJECT] == '/' ? '/' : '' : '' : '';
     $string_to_sign .= rawurldecode($signable_resource) . urldecode($signable_query_string);
     $signature = base64_encode(hash_hmac('sha1', $string_to_sign, $this->access_key, true));
     $request->add_header('Authorization', 'OSS ' . $this->access_id . ':' . $signature);
     if (isset($options[self::OSS_PREAUTH]) && (int) $options[self::OSS_PREAUTH] > 0) {
         $signed_url = $this->request_url . $conjunction . self::OSS_URL_ACCESS_KEY_ID . '=' . rawurlencode($this->access_id) . '&' . self::OSS_URL_EXPIRES . '=' . $options[self::OSS_PREAUTH] . '&' . self::OSS_URL_SIGNATURE . '=' . rawurlencode($signature);
         return $signed_url;
     } elseif (isset($options[self::OSS_PREAUTH])) {
         return $this->request_url;
     }
     if ($this->debug_mode) {
         $request->debug_mode = $this->debug_mode;
     }
     $request->send_request();
     $response_header = $request->get_response_header();
     $response_header['oss-request-url'] = $this->request_url;
     $response_header['oss-redirects'] = $this->redirects;
     $response_header['oss-stringtosign'] = $string_to_sign;
     $response_header['oss-requestheaders'] = $request->request_headers;
     $data = new ResponseCore($response_header, $request->get_response_body(), $request->get_response_code());
     //retry if OSS Internal Error
     if ((int) $request->get_response_code() === 500) {
         if ($this->redirects <= $this->max_retries) {
             //设置休眠
             $delay = (int) (pow(4, $this->redirects) * 100000);
             usleep($delay);
             $this->redirects++;
             $data = $this->auth($options);
         }
     }
     $this->redirects = 0;
     return $data;
 }
开发者ID:codingoneapp,项目名称:codingone,代码行数:101,代码来源:sdk.class.php


注:本文中的RequestCore::send_request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。