开发者社区> 问答> 正文

图片处理签名出错,按照文档做的,帮忙看看是不是哪里弄错?

以下为错误提示:


This XML file does not appear to have any style information associated with it. The document tree is shown below.


<Error>

<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<RequestId>54544E4165CC6367EB0DD555</RequestId>
<HostId>image.soso88.org</HostId>
</Error>


-----------------------------------------------------------分割线-----------------------------------------------------


以下为代码片段:

/**      * 实现阿里云签名实现以及相关URL请求必要的URL参数,参数使用在URL的?号后面部分。
     * 此处实现的URL是基于网络抓取频道下的URL链接      * @param key        访问的资源文件名
     * @param param        访问的资源图片处理参数(OSS协议对图片的处理)      * @param time        访问的URL有效时间,过期后访问URL无效
     * @return            返回最终的URL参数(OSS协议)      * @throws UnsupportedEncodingException
     */     public static String getDownLoadUrlStr(String key,String param, int time) throws UnsupportedEncodingException{
        StringBuffer urlBuf = new StringBuffer();         int realtime = DateUtilExt.parseNowToInt()+time;
        urlBuf.append("OSSAccessKeyId=").append(URLEncoder.encode(ACCESS_ID, "utf-8"));         urlBuf.append("&");
        urlBuf.append("Expires=").append(realtime);         urlBuf.append("&");
        String canonicalizedResource = "/" + downloadBucketName + "/" + key + "@" + param;         urlBuf.append("Signature=").append(URLEncoder.encode(getSignature(canonicalizedResource, realtime), "utf-8"));
        return urlBuf.toString();     }


public static final String GET_METHOD = "GET";    private static String getSignature(String canonicalizedResource, int time){
        StringBuffer buf = new StringBuffer();        buf.append(GET_METHOD);
        buf.append("\n");        buf.append("\n");
        buf.append("\n");        buf.append(time);
        buf.append("\n");        buf.append(canonicalizedResource);
        return Codec.encodeBASE64(buf.toString());    }

展开
收起
正武 2014-11-01 11:18:44 7328 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载