桶相关接口 功能说明 跨域资源共享 (CORS) 定义了在一个域中加载的客户端 Web 应用程序与另一个域中的资源交互的方式。利用 CORS 支持,您可以构建丰富的客户端 Web 应用程序,同时可以选择性地允许跨源访问您的资源。 您可以通过GetCORSConfiguration接口设置桶的跨域访问配置。 代码示例 plaintext using System; using System.Threading.Tasks; using Amazon.Runtime; using Amazon.S3; namespace DotNetSDK.BucketOperation { public class GetBucketCORSExample { public static async Task GetCORSConfiguration() { var accessKey " "; var secretKey " "; var endpoint " "; var bucketName " "; try { var credentials new BasicAWSCredentials(accessKey, secretKey); var conf new AmazonS3Config { ServiceURL endpoint }; var s3Client new AmazonS3Client(credentials, conf); var result await s3Client.GetCORSConfigurationAsync(bucketName); if (result.HttpStatusCode ! System.Net.HttpStatusCode.OK) { Console.WriteLine("fail to get bucket cors {0}, HttpStatusCode:{1}, ErrorCode:{2}.", bucketName, (int) result.HttpStatusCode, result.HttpStatusCode); return; } foreach (var corsRule in result.Configuration.Rules) { Console.WriteLine("cors rule's methods: {0}", string.Join(", ", corsRule.AllowedMethods)); Console.WriteLine("cors rule's headers: {0}", string.Join(", ", corsRule.AllowedHeaders)); Console.WriteLine("cors rule's origins: {0}", string.Join(", ", corsRule.AllowedOrigins)); Console.WriteLine("cors rule's expose headers: {0}", string.Join(", ", corsRule.ExposeHeaders)); Console.WriteLine("cors rule's expired seconds: {0}", corsRule.MaxAgeSeconds); } } catch (Exception e) { Console.WriteLine(e.Message); } } } } 请求参数 参数 类型 说明 是否必要 bucketName string 桶名称 是