首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在使用云解析的添加域名时,请求返回为4100,请问怎么配置请求签名?

在使用云解析的添加域名时,请求返回为4100,请问怎么配置请求签名?

提问于 2018-10-31 14:42:58
回答 2关注 0查看 421

使用云解析的添加域名时,参照官方的请求签名文档进行的排序和编码,但是在调用后返回的却是4100详细代码如下:

String strUrl = "POSTcns.api.qcloud.com/v2/index.php?Action=DomainCreate&Nonce=9572234&Region=gz&SecretId=AKIDQQaiqoMirwPj07NMzCjLw5MavV4TDs18&SignatureMethod=HmacSHA1&Timestamp=1540956598";
try {
            //进行HmacSHA1编码
            SecretKeySpec signKey = new SecretKeySpec(strSecretKey.getBytes("utf-8"),"HmacSHA1");
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(signKey);
            byte[] rawHmac = mac.doFinal(strUrl.getBytes("utf-8"));
            System.out.println(Hex.encodeHexString(rawHmac));
            //64位编码后的Signature
            String text = Base64.getEncoder().encodeToString(rawHmac);
            System.out.println(text);
            //url编码后的Signature
            String urlText = java.net.URLEncoder.encode(text,"utf-8");
            System.out.println(urlText);
            //请求的url
            String requestUrl = "https://cns.api.qcloud.com/v2/index.php";
            HttpClient client = new HttpClient();
            PostMethod post = new PostMethod(requestUrl);
            //在头文件中设置转码
            post.addRequestHeader("Content-Type", format);
            //请求参数
            NameValuePair[] data = {
                    new NameValuePair("Action","DomainCreate"),
                    new NameValuePair("SecretId","AKIDQQaiqoMirwPj07NMzCjLw5MavV4TDs18"),
                    new NameValuePair("Region","ap-guangzhou"),
                    new NameValuePair("Timestamp","1540956598"),
                    new NameValuePair("Nonce","9572234"),
                    new NameValuePair("Signature",urlText),
                    new NameValuePair("SignaMethod","HmacSHA1"),
                    new NameValuePair("domain","dev.test.com"),
                    new NameValuePair("projectId","0"),
            };
            post.setRequestBody(data);
            client.executeMethod(post);
            //打印返回头
            Header[] headers = post.getResponseHeaders();
            for (Header h : headers) {
                System.out.println(h.toString());
            }
            //获取返回体
            String result = new String(post.getResponseBodyAsString().getBytes("utf-8"));
            System.out.println("result:" + result);
            post.releaseConnection();

        } catch (Exception e) {
            e.printStackTrace();
        }

请帮忙解答下,谢谢

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档