Static Website

Last updated: 2020-03-20 10:29:50

PDF

Note

This document provides an overview of API on static websites and sample SDK code.

API Operation name pedagogical operation
PUT Bucket website Setting up a Static Website Set Bucket's static website configuration
GET Bucket website Query static site configuration Query Bucket's static website configuration
DELETE Bucket website Delete static site configuration Delete Bucket's static website configuration

Setting up a Static Website

Function description

PUT Bucket website is used to configure a static website for Bucket.

Method prototype

PutBucketWebsiteResult putBucketWebsite(PutBucketWebsiteRequest request);

void putBucketWebsiteAsync(PutBucketWebsiteRequest 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"; 
  PutBucketWebsiteRequest putRequest = new PutBucketWebsiteRequest(instance.bucketForBucketTest);
  putRequest.SetIndexDocument("index.html");
  putRequest.SetErrorDocument("eroror.html");
  putRequest.SetRedirectAllRequestTo("index.html");
  PutBucketWebsiteResult putResult = cosXml.putBucketWebsite(putRequest);

  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 Bucket of the static website in BucketName-APPID format. For more information, please see Naming convention String
IndexDocument Index document String
ErrorDocument Error document String
RedirectAllRequestsTo Redirect all requests String
Rules Redirection rule Object

Return result description

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

Query static site configuration

Function description

GET Bucket website is used to query static website configuration information with Bucket and Associate.

Method prototype

etBucketWebsiteResult getBucketWebsite(GetBucketWebsiteRequest request);

void getBucketWebsiteAsync(GetBucketWebsiteRequest 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"; 
  DeleteBucketTaggingRequest request = new DeleteBucketTaggingRequest(bucket);   
  DeleteBucketTaggingResult result = cosXml.deleteBucketTagging(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 Query Bucket configured on a static website in BucketName-APPID format. For more information, please see Naming convention Xxx

Return result description

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

Delete static site configuration

Function description

DELETE Bucket website is used to delete the static website configuration in Bucket.

Method prototype

DeleteBucketWebsiteResult deleteBucketWebsite(DeleteBucketWebsiteRequest request);

void deleteBucketWebsiteAsync(DeleteBucketWebsiteRequest 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"; 
  DeleteBucketTaggingRequest request = new DeleteBucketTaggingRequest(bucket);   
  DeleteBucketTaggingResult result = cosXml.deleteBucketTagging(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 Bucket, whose static website configuration is deleted, is 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