文档首页 > > SDK参考> .NET> 跨域资源共享>

查看跨域规则

查看跨域规则

分享
更新时间:2021/02/08 GMT+08:00

开发过程中,您有任何问题可以在github上提交issue,或者在华为云对象存储服务论坛中发帖求助。接口参考文档详细介绍了每个接口的参数和使用方法。

您可以通过ObsClient.GetBucketCors查看桶的跨域规则。以下代码展示了如何查看跨域规则:

// 创建ObsClient实例
ObsClient client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", "https://your-endpoint");
// 查看跨域规则
try
{
    GetBucketCorsConfigurationRequest request = new GetBucketCorsConfigurationRequest();
    request.BucketName = "bucketname";
    GetBucketCorsResponse response = client.GetBucketCors(request);
    foreach (CorsRule rule in response.Configuration.Rules)
    {
        Console.WriteLine("rule id is: {0}\n", rule.Id);
        foreach (string allowOrigin in rule.AllowedOrigins)
        {
            Console.WriteLine("allowOrigin is: {0}\n", allowOrigin);
        }
        foreach (string allowHeader in rule.AllowedHeaders)
        {
            Console.WriteLine("allowHeader is: {0}\n", allowHeader);
        }
        foreach (HttpVerb allowMethod in rule.AllowedMethods)
        {
            Console.WriteLine("allowMethod is: {0}\n", allowMethod);
        }
        foreach (string exposeHeader in rule.ExposeHeaders)
        {
            Console.WriteLine("exposeHeader is: {0}\n", exposeHeader);
        }
        Console.WriteLine("rule maxAgeSeconds is: {0}\n", rule.MaxAgeSeconds);

    }
}
catch (ObsException ex)
{
    Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
    Console.WriteLine("ErrorMessage: {0}", ex.ErrorMessage);
}
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!非常感谢您的反馈,我们会继续努力做到更好!
反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问