AWS Java SDK错误消息:授权标头格式错误;授权标头需要三个组件

时间:2016-11-10 12:28:46

标签: amazon-web-services amazon-s3 aws-sdk

我在尝试将文件放入AWS存储桶时遇到以下错误

错误消息:授权标头格式错误;授权标头需要三个组件:Credential,SignedHeaders和Signature。 (服务:Amazon S3;状态代码:400;错误代码:AuthorizationHeaderMalformed;请求ID:abc) HTTP状态代码:400 AWS错误代码:AuthorizationHeaderMalformed 错误类型:客户端 请求ID:abc 我正在使用以下代码来完成此任务。知道我做错了什么。

AWSCredentials awsCredentials = new BasicAWSCredentials("key",", "secret");
AmazonS3 s3Client = new AmazonS3Client(awsCredentials);
        s3Client.setRegion(com.amazonaws.regions.Region.getRegion(Regions.US_WEST_2));

String key = "test";
try {
     s3Client.putObject(new PutObjectRequest(bucketName, key, file);

      } catch (AmazonServiceException ase) {

         System.out.println("Error Message:    " + ase.getMessage());
         System.out.println("HTTP Status Code: " + ase.getStatusCode());
         System.out.println("AWS Error Code:   " + ase.getErrorCode());
         System.out.println("Error Type:       " + ase.getErrorType());
         System.out.println("Request ID:       " + ase.getRequestId());
     } catch (AmazonClientException ace) {
         System.out.println("Caught an AmazonClientException, which means the client encountered "
                 + "a serious internal problem while trying to communicate with S3, "
                 + "such as not being able to access the network.");
         System.out.println("Error Message: " + ace.getMessage());
     }

0 个答案:

没有答案