开发者指南

API 文档

SDK 文档

静态网站

最近更新时间:2020-03-06 14:09:16

简介

本文档提供关于静态网站的 API 概览以及 SDK 示例代码。

API 操作名 操作描述
PUT Bucket website 设置静态网站 设置存储桶的静态网站配置
GET Bucket website 查询静态网站配置 查询存储桶的静态网站配置
DELETE Bucket website 删除静态网站配置 删除存储桶的静态网站配置

设置静态网站

功能说明

PUT Bucket website 用于为存储桶配置静态网站。

方法原型

PutBucketWebsiteResult putBucketWebsite(PutBucketWebsiteRequest request);

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

请求示例

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  //设置连接超时时间,单位毫秒,默认45000ms
  .SetReadWriteTimeoutMs(40000)  //设置读写超时时间,单位毫秒,默认45000ms
  .IsHttps(true)  //设置默认 HTTPS 请求
  .SetAppid("1250000000") //设置腾讯云账户的账户标识 APPID
  .SetRegion("ap-guangzhou") //设置一个默认的存储桶地域
  .Build();

string secretId = "COS_SECRETID";   //云 API 密钥 SecretId
string secretKey = "COS_SECRETKEY"; //云 API 密钥 SecretKey
long durationSecond = 600;          //每次请求签名有效时长,单位为秒
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
  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());
}

参数说明

参数名称 描述 类型
bucket 设置静态网站的存储桶,格式为 BucketName-APPID ,详情请参见 命名规范 string
IndexDocument 索引文档 string
ErrorDocument 错误文档 string
RedirectAllRequestsTo 重定向所有请求 string
rules 重定向规则 object

返回结果说明

成员变量 描述 类型
httpCode HTTP Code, [200, 300)之间表示操作成功,否则表示操作失败 int

查询静态网站配置

功能说明

GET Bucket website 用于查询与存储桶关联的静态网站配置信息。

方法原型

etBucketWebsiteResult getBucketWebsite(GetBucketWebsiteRequest request);

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

请求示例

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  //设置连接超时时间,单位毫秒,默认45000ms
  .SetReadWriteTimeoutMs(40000)  //设置读写超时时间,单位毫秒,默认45000ms
  .IsHttps(true)  //设置默认 HTTPS 请求
  .SetAppid("1250000000") //设置腾讯云账户的账户标识 APPID
  .SetRegion("ap-guangzhou") //设置一个默认的存储桶地域
  .Build();

string secretId = "COS_SECRETID";   //云 API 密钥 SecretId
string secretKey = "COS_SECRETKEY"; //云 API 密钥 SecretKey
long durationSecond = 600;          //每次请求签名有效时长,单位为秒
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
  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());
}

参数说明

参数名称 描述 类型
bucket 查询静态网站配置的存储桶,格式为 BucketName-APPID ,详情请参见 命名规范 xxx

返回结果说明

成员变量 描述 类型
httpCode HTTP Code, [200, 300)之间表示操作成功,否则表示操作失败 int

删除静态网站配置

功能说明

DELETE Bucket website 用于删除存储桶中的静态网站配置。

方法原型

DeleteBucketWebsiteResult deleteBucketWebsite(DeleteBucketWebsiteRequest request);

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

请求示例

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  //设置连接超时时间,单位毫秒,默认45000ms
  .SetReadWriteTimeoutMs(40000)  //设置读写超时时间,单位毫秒,默认45000ms
  .IsHttps(true)  //设置默认 HTTPS 请求
  .SetAppid("1250000000") //设置腾讯云账户的账户标识 APPID
  .SetRegion("ap-guangzhou") //设置一个默认的存储桶地域
  .Build();

string secretId = "COS_SECRETID";   //云 API 密钥 SecretId
string secretKey = "COS_SECRETKEY"; //云 API 密钥 SecretKey
long durationSecond = 600;          //每次请求签名有效时长,单位为秒
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
  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());
}

参数说明

参数名称 描述 类型
bucket 被删除静态网站配置的存储桶,格式为 BucketName-APPID ,详情请参见 命名规范 string

返回结果说明

成员变量 描述 类型
httpCode HTTP Code, [200, 300)之间表示操作成功,否则表示操作失败 int
目录