Custom Domain

Last updated: 2020-03-20 10:59:25

PDF

Note

This document provides an overview of API for custom domain names and sample SDK code.

API Operation name pedagogical operation
PUT Bucket domain Set up a custom domain name Set Bucket's custom domain name information
GET Bucket domain Query custom domain name Query Bucket's custom domain name information

Set up a custom domain name

Function description

PUT Bucket domain is used to configure a custom domain name for Bucket.

Method prototype

PutBucketDomainResult putBucketDomain(PutBucketDomainRequest request);

void putBucketDomainAsync(PutBucketDomainRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("ap-guangzhou") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;         
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string 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);   
  PutBucketDomainResult result = cosXml.putBucketDomain(request);

  Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
  Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
  Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

Parameter description

Parameter name Description Type
Bucket Set the custom domain name Bucket in BucketName-APPID format. For more information, please see Naming convention String
Name Custom Domain String
Status Domain name Activate status. Available values include ENABLED and DISABLED String
Type The type of real server bound. Available values include REST and WEBSITE. String
Replace Forced overwrite of existing configurations. Available values include CNAME and TXT String

Return result description

Member variable Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) , otherwise it failed Int

Returns the error code description

Some common special errors that may occur in this request are as follows:

Status Code Description
HTTP 409 Conflict The domain name record already exists and no mandatory overwrite is set in the request. Or the domain name record does not exist and a forced overwrite is set in the request
HTTP 451 Unavailable For Legal Reasons The domain name is a domain name within China, and there is no ICP filing.

Query custom domain name

Function description

GET Bucket domain is used to query Bucket's custom domain name information.

Method prototype

GetBucketDomainResult getBucketDomain(GetBucketDomainRequest request);

void getBucketDomainAsync(GetBucketDomainRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("ap-guangzhou") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;          
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string bucket = "examplebucket-1250000000"; 
  GetBucketDomainRequest request = new GetBucketDomainRequest(bucket);   
  GetBucketDomainResult result = cosXml.getBucketDomain(request);

  Console.WriteLine(result.domainConfiguration);
}
catch (COSXML.CosException.CosClientException clientEx)
{
  Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
  Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

Parameter description

Parameter name Description Type
Bucket Query the Bucket of the custom domain name in BucketName-APPID format. For more information, please see Naming convention String

Return result description

Member variable Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) , otherwise it failed Int

Return parameter description

Parameter nameDescriptionType
X-cos-domain-txt-verificationDomain name verification information. This field is a MD5 check value. The original string format is:Cos [Region] [BucketName-APPID] [BucketCreateTime]Where Region is the region where Bucket is located, and BucketCreateTime is the creation time of Bucket GMTString