History
Introduction
API Category
Making API Requests
Region APIs
Instance APIs
Cloud Hosting Cluster APIs
Image APIs
Instance Launch Template APIs
Placement Group APIs
Key APIs
Security Group APIs
Network APIs
Data Types
Error Codes
PUT /?cors HTTP/1.1Host: <BucketName-APPID>.cos.<Region>.myqcloud.comDate: GMT DateContent-Type: application/xmlContent-Length: Content LengthContent-MD5: MD5Authorization: Auth String[Request Body]
<CORSConfiguration><CORSRule><AllowedOrigin>string</AllowedOrigin><AllowedMethod>enum</AllowedMethod><AllowedMethod>enum</AllowedMethod><AllowedHeader>string</AllowedHeader><AllowedHeader>string</AllowedHeader><ExposeHeader>string</ExposeHeader><ExposeHeader>string</ExposeHeader><MaxAgeSeconds>integer</MaxAgeSeconds></CORSRule><CORSRule><ID>string</ID><AllowedOrigin>string</AllowedOrigin><AllowedOrigin>string</AllowedOrigin><AllowedMethod>enum</AllowedMethod><AllowedMethod>enum</AllowedMethod><AllowedHeader>string</AllowedHeader><ExposeHeader>string</ExposeHeader><ExposeHeader>string</ExposeHeader><MaxAgeSeconds>integer</MaxAgeSeconds></CORSRule></CORSConfiguration>
节点名称(关键字) | 父节点 | 描述 | 类型 | 是否必选 |
CORSConfiguration | 无 | 包含 PUT Bucket cors 操作的所有请求信息 | Container | 否 |
节点名称(关键字) | 父节点 | 描述 | 类型 | 是否必选 |
CORSRule | CORSConfiguration | 说明单条跨域资源共享(CORS)配置的所有信息,最多可以包含100条 CORSRule | Container | 是 |
节点名称(关键字) | 父节点 | 描述 | 类型 | 是否必选 |
AllowedOrigin | CORSConfiguration.CORSRule | 允许的访问来源,单条 CORSRule 可以配置多个 AllowedOrigin。 配置支持 *,表示全部域名都允许,但不推荐。支持单个具体域名,例如 http://www.example.com。支持 * 通配符,通配符可出现在任何位置,包括协议、域名和端口,可匹配0个或多个字符,但是只能有一个 *。请谨慎使用通配符,因为可能意外匹配到非预期的来源注意不要遗漏协议名 http 或 https,若端口不是默认的80(http)或443(https),还需要带上端口,例如 https://example.com:8443。 | string | 是 |
AllowedMethod | CORSConfiguration.CORSRule | 允许的 HTTP 操作方法(Method),对应 CORS 请求响应中的 Access-Control-Allow-Methods 头部,单条 CORSRule 可以配置多个 AllowedMethod。枚举值:PUT、GET、POST、DELETE、HEAD。 | enum | 是 |
AllowedHeader | CORSConfiguration.CORSRule | 在发送预检(OPTIONS)请求时,浏览器会告知服务端接下来的正式请求将使用的自定义 HTTP 请求头部,此配置用于指定允许浏览器发送 CORS 请求时携带的自定义 HTTP 请求头部,不区分英文大小写,单条 CORSRule 可以配置多个 AllowedHeader。 可以配置 *,代表允许所有头部,为了避免遗漏,推荐配置为*。如果不配置为 *,那么在预检(OPTIONS)请求中 Access-Control-Request-Headers 头部出现的每个 Header,都必须在 AllowedHeader 中有对应项。 | string | 是 |
ExposeHeader | CORSConfiguration.CORSRule | 允许浏览器获取的 CORS 请求响应中的头部,不区分大小写,单条 CORSRule 可以配置多个 ExposeHeader。 默认情况下浏览器只能访问简单响应头部:Cache-Control、Content-Type、Expires、Last-Modified,如果需要访问其他响应头部,需要添加 ExposeHeader 配置。 不支持配置为 *,必须明确配置具体的 Header。根据浏览器的实际需求确定,默认推荐填写 ETag,可参考各 API 文档的响应头部分及 公共响应头部 文档。 | string | 是 |
MaxAgeSeconds | CORSConfiguration.CORSRule | 跨域资源共享配置的有效时间,单位为秒,在有效时间内,浏览器无须为同一请求再次发起预检(OPTIONS)请求,对应 CORS 请求响应中的 Access-Control-Max-Age 头部,单条 CORSRule 只能配置一个 MaxAgeSeconds。 | integer | 是 |
ID | CORSConfiguration.CORSRule | 单条 CORSRule 配置的 ID,用于在 GET Bucket cors 时查找指定 CORSRule。可选填,单条 CORSRule 最多配置一个 ID。 | string | 否 |
PUT /?cors HTTP/1.1Host: examplebucket-1250000000.cos.ap-beijing.myqcloud.comDate: Thu, 09 Jul 2020 11:15:01 GMTContent-Type: application/xmlContent-Length: 1185Content-MD5: ZNkhBxyjkaZcs1j7/cIE2A==Authorization: q-sign-algorithm=sha1&q-ak=AKID8A0fBVtYFrNm02oY1g1JQQF0c3JO****&q-sign-time=1594293301;1594300501&q-key-time=1594293301;1594300501&q-header-list=content-length;content-md5;content-type;date;host&q-url-param-list=cors&q-signature=2ec71624468abfbd5c8ea2679e1365b29f3a****Connection: close<CORSConfiguration><CORSRule><AllowedOrigin>*</AllowedOrigin><AllowedMethod>GET</AllowedMethod><AllowedMethod>HEAD</AllowedMethod><AllowedHeader>Range</AllowedHeader><AllowedHeader>x-cos-server-side-encryption-customer-algorithm</AllowedHeader><AllowedHeader>x-cos-server-side-encryption-customer-key</AllowedHeader><AllowedHeader>x-cos-server-side-encryption-customer-key-MD5</AllowedHeader><ExposeHeader>Content-Length</ExposeHeader><ExposeHeader>ETag</ExposeHeader><ExposeHeader>x-cos-meta-author</ExposeHeader><MaxAgeSeconds>600</MaxAgeSeconds></CORSRule><CORSRule><ID>example-id</ID><AllowedOrigin>https://example.com</AllowedOrigin><AllowedOrigin>https://example.net</AllowedOrigin><AllowedMethod>PUT</AllowedMethod><AllowedMethod>GET</AllowedMethod>...<AllowedMethod>HEAD</AllowedMethod><AllowedHeader>*</AllowedHeader><ExposeHeader>Content-Length</ExposeHeader><ExposeHeader>ETag</ExposeHeader><ExposeHeader>x-cos-meta-author</ExposeHeader><MaxAgeSeconds>600</MaxAgeSeconds></CORSRule></CORSConfiguration>
HTTP/1.1 200 OKContent-Length: 0Connection: closeDate: Thu, 09 Jul 2020 11:15:01 GMTServer: tencent-cosx-cos-request-id: NWYwNmZjMzVfMzFiYjBiMDlfZjgzYV8xZDky****
文档反馈