问题描述
在调用创建容器"时遇到以下错误.
Getting the below error while making a call to Create Container.
响应码:403响应消息:服务器无法验证请求.请确保正确构成Authorization标头的值(包括签名).
Response Code : 403Response Message : Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
String stringToSign = "PUT\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" + date + "\nx-ms-version:" + "2018-03-28\nx-ms-lease-action:acquire\nx-ms-lease-duration:1\nx-ms-proposed-lease-id:1f812371-a41d-49e6-b123-f4b542e851c5\n" + "/" + storageAccount + "/"+ "container-lease-test"+"\ncomp:lease";
Java代码段
HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection();
connection.setRequestMethod(vMethod);
connection.addRequestProperty("Authorization", authHeader);
connection.addRequestProperty("x-ms-date", date);
connection.addRequestProperty("x-ms-version", "2018-03-28");
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(0);
//Create Lease
connection.addRequestProperty("x-ms-lease-action", "acquire");
connection.addRequestProperty("x-ms-lease-duration","1");
connection.addRequestProperty("x-ms-proposed-lease-id","1f812371-a41d-49e6-b123-f4b542e851c5");
推荐答案
我们需要按标题名称按字母顺序对x-ms- *标题进行升序排序.而且您也错过了最后的重新输入.
We need to sort the x-ms-* headers lexicographically by header name, in ascending order. And also you missed restype at the end.
String stringToSign = "PUT\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" + date + "\nx-ms-lease-action:acquire\nx-ms-lease-duration:15\nx-ms-proposed-lease-id:1f812371-a41d-49e6-b123-f4b542e851c5\nx-ms-version:2018-03-28\n/" + storageAccount + "/container-lease-test\ncomp:lease\nrestype:container";
此外,x-ms-lease-duration
应该为15〜60或-1(无穷大).
Besides, x-ms-lease-duration
should be 15~60 or -1(infinite).
我建议您遵循 docs 并使用提琴手来捕获流量,如果出现403错误,则可以看到预期的stringtosign.然后您就可以享受快速调试了.
I recommend you to follow docs and use Fiddler to catch traffic, you can see expected stringtosign if you get 403 error. Then you can enjoy quick debug.
这篇关于Azure存储服务REST API:创建租约的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!