文档首页> OBS PHP SDK> API参考> 桶相关接口> 获取桶的CORS配置
更新时间:2021-03-18 GMT+08:00
分享

获取桶的CORS配置

功能说明

获取指定桶的跨域资源共享规则。

方法定义

1. ObsClient->setBucketCors(array $parameter)
2. ObsClient->setBucketCorsAsync(array $parameter, callable $callback)

请求参数

字段名

类型

约束

说明

Bucket

string

必选

桶名。

返回结果

字段名

类型

说明

HttpStatusCode

integer

HTTP状态码。

Reason

string

HTTP文本描述。

RequestId

string

OBS服务端返回的请求ID。

CorsRules

indexed array

桶的CORS规则列表。

  

ID

string

CORS规则ID。

AllowedMethod

indexed array of strings

CORS规则允许的HTTP方法。

AllowedOrigin

indexed array of strings

CORS规则允许的请求来源(表示域名的字符串)。

AllowedHeader

indexed array of strings

CORS规则允许请求中可携带的头域。

MaxAgeSecond

integer

CORS规则允许客户端可以对跨域请求返回结果的缓存时间,以秒为单位。

ExposeHeader

indexed array of strings

CORS规则允许响应中可返回的附加头域。

代码样例

try{
       $resp = $obsClient -> getBucketCors([
              'Bucket' => 'bucketname'
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
       foreach ($resp['CorsRules'] as $index => $corsRule){
              printf("CorsRule[%d]\n", $index + 1);
              printf("MaxAgeSeconds:%s\n", print_r($corsRule['MaxAgeSeconds'], true));
              printf("AllowedMethod:%s\n", print_r($corsRule['AllowedMethod'], true));
              printf("AllowedOrigin:%s\n", print_r($corsRule['AllowedOrigin'], true));
              printf("AllowedHeader:%s\n", print_r($corsRule['AllowedHeader'], true));
              printf("ExposeHeader:%s\n", print_r($corsRule['ExposeHeader'],true));
       }
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());              
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}
分享:

    相关文档

    相关产品