/// 获取存储桶自定义域名 public void GetBucketDomain() { //.cssg-snippet-body-start:[get-bucket-domain] try { string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID 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()); } //.cssg-snippet-body-end }
public void TestBucketDomain() { bool setDomain = false; try { DomainConfiguration domain = new DomainConfiguration(); domain.rule = new DomainConfiguration.DomainRule(); domain.rule.Name = "www.qq.com"; domain.rule.Status = "ENABLED"; domain.rule.Type = "WEBSITE"; domain.rule.Replace = ""; PutBucketDomainResult result = cosXml.PutBucketDomain(new PutBucketDomainRequest(bucket, domain)); Assert.AreEqual(result.httpCode, 200); setDomain = true; } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.Fail(); } catch (COSXML.CosException.CosServerException serverEx) { if (serverEx.statusCode != 409 && serverEx.statusCode != 451) { Assert.Fail(); } } try { GetBucketDomainResult getResult = cosXml.GetBucketDomain(new GetBucketDomainRequest(bucket)); // Console.WriteLine(getResult.GetResultInfo()); Assert.IsNotEmpty((getResult.GetResultInfo())); Assert.AreEqual(getResult.httpCode, 200); if (setDomain) { Assert.NotNull(getResult.domainConfiguration.rule); Assert.NotNull(getResult.domainConfiguration.rule.Name); Assert.NotNull(getResult.domainConfiguration.rule.Status); Assert.NotNull(getResult.domainConfiguration.rule.Type); Assert.NotNull(getResult.domainConfiguration.rule.Replace); } else { Assert.Null(getResult.domainConfiguration); } } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.Fail(); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); if (serverEx.statusCode != 409 && serverEx.statusCode != 451) { Assert.Fail(); } } }