简介
本文档提供关于跨域访问的 API 概览以及 SDK 示例代码。
设置跨域配置
功能说明
设置指定存储桶的跨域名访问配置信息(PUT Bucket cors)。
方法原型
public Guzzle\Service\Resource\Model putBucketCors(array $args = array());
请求示例
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID";
$secretKey = "SECRETKEY";
$region = "ap-beijing";
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https',
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$result = $cosClient->putBucketCors(array(
'Bucket' => 'examplebucket-1250000000',
'CORSRules' => array(
array(
'AllowedHeaders' => array('*',),
'AllowedMethods' => array('PUT', ),
'AllowedOrigins' => array('*', ),
'ExposeHeaders' => array('*', ),
'MaxAgeSeconds' => 1,
),
)
));
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";
$secretKey = "SECRETKEY";
$region = "ap-beijing";
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https',
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$result = $cosClient->getBucketCors(array(
'Bucket' => 'examplebucket-1250000000'
));
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:
)
)
)
[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";
$secretKey = "SECRETKEY";
$region = "ap-beijing";
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https',
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$result = $cosClient->deleteBucketCors(array(
'Bucket' => 'examplebucket-1250000000'
));
print_r($result);
} catch (\Exception $e) {
echo($e);
}
参数说明
参数名称 |
类型 |
描述 |
是否必填 |
Bucket |
String |
被删除跨域配置的存储桶,格式:BucketName-APPID |
是 |
本页内容是否解决了您的问题?