简介
本文档提供关于跨域访问的 API 概览以及 SDK 示例代码。
API | 操作名 | 操作描述 |
PUT Bucket cors | 设置跨域配置 | 设置存储桶的跨域名访问权限 |
GET Bucket cors | 查询跨域配置 | 查询存储桶的跨域名访问配置信息 |
DELETE Bucket cors | 删除跨域配置 | 删除存储桶的跨域名访问配置信息 |
设置跨域配置
功能说明
设置指定存储桶的跨域名访问配置信息(PUT Bucket cors)。关于跨域访问的更多说明请参见 跨域访问,通过控制台设置跨域的操作步骤请参见 设置跨域访问 或 跨域访问最佳实践文档。
方法原型
public Guzzle\Service\Resource\Model putBucketCors(array $args = array());
请求示例
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket$cosClient = new Qcloud\Cos\Client( array( 'region' => $region, 'scheme' => 'https', //协议头部,默认为http 'credentials'=> array( 'secretId' => $secretId , 'secretKey' => $secretKey)));
try { $result = $cosClient->putBucketCors(array( 'Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket 'CORSRules' => array( array( 'AllowedHeaders' => array('*',), 'AllowedMethods' => array('PUT', ), 'AllowedOrigins' => array('*', ), 'ExposeHeaders' => array('*', ), 'MaxAgeSeconds' => 1, ), // ... repeated ) )); // 请求成功 print_r($result);} catch (\Exception $e) { // 请求失败 echo "$e\n";}
参数说明
参数名称 | 类型 | 描述 | 是否必填 |
Bucket | String | 设置跨域配置的存储桶,格式:BucketName-APPID | 是 |
CORSRules | Array | 跨域信息列表 | 是 |
CORSRule | Array | 跨域信息 | 是 |
AllowedMethods | String | 允许的 HTTP 操作,枚举值:GET,PUT,HEAD,POST,DELETE | 是 |
AllowedOrigins | String | 允许的访问来源,支持通配符* , 格式:协议://域名[:端口] ,例如http://www.qq.com |
是 |
AllowedHeaders | String | 在发送 OPTIONS 请求时告知服务端,接下来的请求可以使用哪些自定义的 HTTP 请求头部,支持通配符* |
否 |
ExposeHeaders | String | 设置浏览器可以接收到来自服务器端的自定义头部信息 | 否 |
MaxAgeSeconds | Int | 设置 OPTIONS 请求得到结果的有效期 | 否 |
ID | String | 配置规则的 ID | 是 |
查询跨域配置
功能说明
查询指定存储桶的跨域名访问配置信息(GET Bucket cors)。
方法原型
public Guzzle\Service\Resource\Model getBucketCors(array $args = array());
请求示例
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket$cosClient = new Qcloud\Cos\Client( array( 'region' => $region, 'scheme' => 'https', //协议头部,默认为http 'credentials'=> array( 'secretId' => $secretId , 'secretKey' => $secretKey)));
try { $result = $cosClient->getBucketCors(array( 'Bucket' => 'examplebucket-1250000000' //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket )); // 请求成功 print_r($result);} catch (\Exception $e) { // 请求失败 echo($e);}
参数说明
参数名称 | 类型 | 描述 | 是否必填 |
Bucket | String | 查询跨域配置的存储桶,格式:BucketName-APPID | 是 |
返回结果示例
Guzzle\Service\Resource\Model Object( [data:protected] => Array ( [CORSRules] => Array ( [0] => Array ( [ID] => 1234 [AllowedHeaders] => Array ( [0] => * ) [AllowedMethods] => Array ( [0] => PUT ) [AllowedOrigins] => Array ( [0] => http://www.qq.com ) ) ) [RequestId] => NWE3YzhkMmRfMTdiMjk0MGFfNTQzZl8xNWUw**** ))
返回结果说明
参数名称 | 类型 | 描述 | 父节点 |
CORSRules | Array | 跨域信息列表 | 无 |
CORSRule | Array | 跨域信息 | CORSRules |
AllowedMethods | String | 允许的 HTTP 操作,枚举值:GET,PUT,HEAD,POST,DELETE | CORSRule |
AllowedOrigins | String | 允许的访问来源,支持通配符* , 格式:协议://域名[:端口] ,例如http://www.qq.com |
CORSRule |
AllowedHeaders | String | 在发送 OPTIONS 请求时告知服务端,接下来的请求可以使用哪些自定义的 HTTP 请求头部,支持通配符* |
CORSRule |
ExposeHeaders | String | 设置浏览器可以接收到来自服务器端的自定义头部信息 | CORSRule |
MaxAgeSeconds | Int | 设置 OPTIONS 请求得到结果的有效期 | CORSRule |
ID | String | 配置规则的 ID | CORSRule |
删除跨域配置
功能说明
删除指定存储桶的跨域名访问配置(DELETE Bucket cors)。
方法原型
public Guzzle\Service\Resource\Model deleteBucketCors(array $args = array());
请求示例
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket$cosClient = new Qcloud\Cos\Client( array( 'region' => $region, 'scheme' => 'https', //协议头部,默认为http 'credentials'=> array( 'secretId' => $secretId , 'secretKey' => $secretKey)));
try { $result = $cosClient->deleteBucketCors(array( 'Bucket' => 'examplebucket-1250000000' //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket )); // 请求成功 print_r($result);} catch (\Exception $e) { // 请求失败 echo($e);}
参数说明
参数名称 | 类型 | 描述 | 是否必填 |
Bucket | String | 被删除跨域配置的存储桶,格式:BucketName-APPID | 是 |
对象存储官网1折活动,限时活动,即将结束,速速收藏
同尘科技为腾讯云授权服务中心。
购买腾讯云产品享受折上折,更有现金返利。同意关联立享优惠
转转请注明出处:https://www.yunxiaoer.com/145934.html