gpt4 book ai didi

java - Azure 存储服务 REST API : Create Lease

转载 作者:行者123 更新时间:2023-12-02 10:52:01 26 4
gpt4 key购买 nike

调用创建容器时出现以下错误。

响应代码:403响应消息:服务器无法验证请求。确保授权 header 的值格式正确,包括签名。

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");

最佳答案

我们需要按 header 名称的字典顺序对 x-ms-* header 进行升序排序。而且您最后还错过了重新输入。

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(无限)。

推荐您关注docs并使用Fiddler为了捕获流量,如果出现 403 错误,您可以看到预期的 stringtosign。然后您就可以享受快速调试了。

关于java - Azure 存储服务 REST API : Create Lease,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52100823/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com