API | 操作名 | 操作描述 |
设置跨域配置 | 设置存储桶的跨域名访问权限 | |
查询跨域配置 | 查询存储桶的跨域名访问配置信息 | |
删除跨域配置 | 删除存储桶的跨域名访问配置信息 |
try{// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000";PutBucketCORSRequest request = new PutBucketCORSRequest(bucket);//设置跨域访问配置 CORSCOSXML.Model.Tag.CORSConfiguration.CORSRule corsRule =new COSXML.Model.Tag.CORSConfiguration.CORSRule();corsRule.id = "corsconfigureId";corsRule.maxAgeSeconds = 6000;corsRule.allowedOrigins = new List<string>();corsRule.allowedOrigins.Add("http://cloud.tencent.com");corsRule.allowedMethods = new List<string>();corsRule.allowedMethods.Add("PUT");corsRule.allowedHeaders = new List<string>();corsRule.allowedHeaders.Add("Host");corsRule.exposeHeaders = new List<string>();corsRule.exposeHeaders.Add("x-cos-meta-x1");request.SetCORSRule(corsRule);//执行请求PutBucketCORSResult result = cosXml.PutBucketCORS(request);//请求成功Console.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000";GetBucketCORSRequest request = new GetBucketCORSRequest(bucket);//执行请求GetBucketCORSResult result = cosXml.GetBucketCORS(request);//存储桶的 CORS 配置信息CORSConfiguration conf = result.corsConfiguration;}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000";DeleteBucketCORSRequest request = new DeleteBucketCORSRequest(bucket);//执行请求DeleteBucketCORSResult result = cosXml.DeleteBucketCORS(request);//请求成功Console.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
本页内容是否解决了您的问题?