更新时间:2024-12-09 GMT+08:00

查看托管配置

开发过程中,您有任何问题可以在github上提交issue接口参考文档详细介绍了每个接口的参数和使用方法。

您可以通过ObsClient->getBucketWebsite查看桶的托管配置。

本示例用于查看桶名为“bucketname”的托管配置。

代码示例如下所示:

// 引入依赖库
require 'vendor/autoload.php';
// 使用源码安装时引入SDK代码库
// require 'obs-autoloader.php';
// 声明命名空间
use Obs\ObsClient;
// 创建ObsClient实例
$obsClient = new ObsClient ( [ 
      //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。
      //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/intl/zh-cn/usermanual-ca/ca_01_0003.html
      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

$resp = $obsClient->getBucketWebsite ( [ 
       'Bucket' => 'bucketname' 
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
printf ( "IndexDocument[Suffix]:%s\n", $resp ['IndexDocument'] ['Suffix'] );
printf ( "ErrorDocument[Key]:%s\n", $resp ['ErrorDocument'] ['Key'] );
foreach ( $resp ['RoutingRules'] as $index => $routingRule ) {
       printf ( "RoutingRules[%d]\n", $index + 1 );
       printf ( "Condition[HttpErrorCodeReturnedEquals]:%s\n", $routingRule ['Condition'] ['HttpErrorCodeReturnedEquals'] );
       printf ( "Condition[KeyPrefixEquals]:%s\n", $routingRule ['Condition'] ['KeyPrefixEquals'] );
       printf ( "Redirect[HostName]:%s\n", $routingRule ['Redirect'] ['HostName'] );
       printf ( "Redirect[Protocol]:%s\n", $routingRule ['Redirect'] ['Protocol'] );
       printf ( "Redirect[HttpRedirectCode]:%s\n", $routingRule ['Redirect'] ['HttpRedirectCode'] );
       printf ( "Redirect[ReplaceKeyPrefixWith]:%s\n", $routingRule ['Redirect'] ['ReplaceKeyPrefixWith'] );
       printf ( "Redirect[ReplaceKeyWith]:%s\n", $routingRule ['Redirect'] ['ReplaceKeyWith'] );
}
  • 查看桶托管配置过程中返回的错误码含义、问题原因及处理措施可参考OBS服务端错误码