Custom Domain

Last updated: 2020-03-20 12:31:01

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) throws CosXmlClientException, CosXmlServiceException;

void putBucketDomainAsync(PutBucketDomainRequest request, CosXmlResultListener cosXmlResultListener);

Request Sample

String bucket = "examplebucket-1250000000"; 
PutBucketDomainRequest putBucketDomainRequest = new PutBucketDomainRequest(bucket);
DomainConfiguration.DomainRule domainRule = new DomainConfiguration.DomainRule(
        DomainConfiguration.STATUS_ENABLED,
        "www.example.com",
        DomainConfiguration.TYPE_REST
);
domainRule.forcedReplacement = DomainConfiguration.REPLACE_CNAME;
putBucketDomainRequest.addDomainRule(domainRule);

try {
    PutBucketDomainResult putBucketDomainResult = cosXmlService.putBucketDomain(putBucketDomainRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

cosXmlService.putBucketDomainAsync(putBucketDomainRequest, new CosXmlResultListener() {
    @Override
    public void onSuccess(CosXmlRequest request, CosXmlResult result) {
        PutBucketDomainResult putBucketDomainResult = (PutBucketDomainResult) result;
    }

    @Override
    public void onFail(CosXmlRequest cosXmlRequest, CosXmlClientException clientException, CosXmlServiceException serviceException)  {
    }
});

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
ForcedReplacement 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) throws CosXmlClientException, CosXmlServiceException;

void getBucketDomainAsync(GetBucketDomainRequest request, CosXmlResultListener cosXmlResultListener);

Request Sample

String bucket = "examplebucket-1250000000"; 
GetBucketDomainRequest getBucketDomainRequest = new GetBucketDomainRequest(bucket);
Set<String> headerKeys = new HashSet<>();
headerKeys.add("Host");
try {
    GetBucketDomainResult getBucketTaggingResult = cosXmlService.getBucketDomain(getBucketDomainRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

cosXmlService.getBucketDomainAsync(getBucketDomainRequest, new CosXmlResultListener() {
    @Override
    public void onSuccess(CosXmlRequest request, CosXmlResult result) {
        GetBucketDomainResult getBucketTaggingResult = (GetBucketDomainResult)result;
    }

    @Override
    public void onFail(CosXmlRequest cosXmlRequest, CosXmlClientException clientException, CosXmlServiceException serviceException)  {
    }
});

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
DomainConfiguration Returns Bucket object DomainConfiguration information DomainConfiguration

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