Feature Overview
This document provides an overview of APIs and SDK code samples for custom domains.
API | Operation | Description |
PUT Bucket domain | Setting a Custom Endpoint | Sets a custom endpoint for a bucket |
GET Bucket domain | Querying a custom endpoint | Queries the custom endpoint of a bucket |
SDK API References
Setting a Custom Endpoint
Note
This API is used to configure a custom endpoint for a bucket.
Sample code
try{// Bucket name, the format must be bucketname-APPID, for obtaining APPID refer to https://console.cloud.tencent.com/developerstring bucket = "examplebucket-1250000000";DomainConfiguration domain = new DomainConfiguration();domain.rule = new DomainConfiguration.DomainRule();domain.rule.Name = "www.qq.com";domain.rule.Status = "ENABLED";domain.rule.Type = "WEBSITE";PutBucketDomainRequest request = new PutBucketDomainRequest(bucket, domain);// Execute the requestPutBucketDomainResult result = cosXml.PutBucketDomain(request);//Request successfulConsole.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){//Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
Note
Error codes
The following describes some common errors that may occur when making requests using this API.
Status code | Note |
HTTP 409 Conflict | The endpoint record already exists, and forced overwrite is not specified in the request; OR the endpoint record does not exist, and forced overwrite is specified in the request |
HTTP 451 Unavailable For Legal Reasons | The domain does not have an ICP filing in the Chinese mainland |
Querying a custom endpoint
Note
This API is used to query the custom endpoint of a bucket.
Sample code
try{// Bucket name, the format must be bucketname-APPID, for obtaining APPID refer to https://console.cloud.tencent.com/developerstring bucket = "examplebucket-1250000000";GetBucketDomainRequest request = new GetBucketDomainRequest(bucket);// Execute the requestGetBucketDomainResult result = cosXml.GetBucketDomain(request);//Request successfulConsole.WriteLine(result.domainConfiguration);}catch (COSXML.CosException.CosClientException clientEx){//Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
Note
Response parameter description
Parameter name | Description | Local Disk Types |
x-cos-domain-txt-verification | Domain verification information, this field is an MD5 checksum value, the original string format is: cos[Region][BucketName-APPID][BucketCreateTime], where Region is the location of the storage bucket, and BucketCreateTime is the storage bucket's GMT creation time. | String |