我按照OSS API文档里面的说法,写了以下这段JAVA代码,总是遇到SignatureDoesNotMatch错误。求助!
HttpClient client = new DefaultHttpClient();
String uri = "http://storage.aliyun.com";
HttpGet httpget = new HttpGet(uri);
String time = DateUtil.formatRfc822Date(new Date());
String req = "GET\n" time "\n" "/";
SecretKeySpec signingKey = new SecretKeySpec(ACCESS_KEY.getBytes("utf-8"),
"HmacSHA1");
Mac mac;
mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
byte[] rawHmac = mac.doFinal(req.getBytes("utf-8"));
String auth = "OSS " ACCESS_ID ":"
new String(Base64.encodeBase64(rawHmac));
httpget.addHeader("Authorization", auth);
httpget.addHeader("Date", time);
HttpResponse response = client.execute(httpget);
HttpEntity en = response.getEntity();
byte[] buffer = new byte[(int) en.getContentLength()];
en.getContent().read(buffer);
String html = new String(buffer, "utf-8");
System.out.println(html);
错误如下:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<StringToSignBytes>47 45 54 0A 0A 0A 53 75 6E 2C 20 30 35 20 41 75 67 20 32 30 31 32 20 30 32 3A 32 38 3A 34 31 20 47 4D 54 0A 2F </StringToSignBytes>
<SignatureProvided>9g /ufOa/QYlU3EHlfHWvc/q6sg=</SignatureProvided>
<StringToSign>GET
Sun, 05 Aug 2012 02:28:41 GMT
/</StringToSign>
<OSSAccessKeyId>aafet0g8vi9gh8fzl9vt3smj</OSSAccessKeyId>
<RequestId>501DDA5A28EE62A4511B2CDC</RequestId>
<HostId>storage.aliyun.com</HostId>
</Error>
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。