Php Azure租赁Blob API 403错误

Php Azure租赁Blob API 403错误,php,azure,azure-storage,Php,Azure,Azure Storage,我正在尝试租赁blob以删除它,但由于发生403错误,我的租赁blob API代码无法工作 生成签名代码(PHP) 错误 HTTP/2 403 content-length: 774 content-type: application/xml server: Microsoft-HTTPAPI/2.0 x-ms-request-id: 98f7dbe2-801e-0017-78f2-b5d325000000 date: Wed, 07 Mar 2018 09:02:11 GMT <?xm

我正在尝试租赁blob以删除它,但由于发生403错误,我的租赁blob API代码无法工作

生成签名代码(PHP)

错误

HTTP/2 403
content-length: 774
content-type: application/xml
server: Microsoft-HTTPAPI/2.0
x-ms-request-id: 98f7dbe2-801e-0017-78f2-b5d325000000
date: Wed, 07 Mar 2018 09:02:11 GMT

<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:98f7dbe2-801e-0017-78f2-b5d325000000
Time:2018-03-07T09:02:12.1896957Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'qaRQQPDc8T8lFCTq5W6ZkjrJoX6W+a419RMd8MWJsUg=' is not the same as any computed signature. Server used following string to sign: 'PUT











x-ms-date:Wed, 07 Mar 2018 09:02:11 GMT
x-ms-lease-action:acquire
x-ms-lease-duration:-1
x-ms-lease-id:49383176-ad23-4f85-acbf-01edcd02d177
x-ms-version:2017-04-17
/myaccount/mycontainer/myblob
comp:lease'.</AuthenticationErrorDetail></Error>

我已经尝试过其他blob服务API,比如get blob,但成功了。所以我认为这些代码有一些错误。请帮助我。

我认为问题在于
内容长度
请求头。请将
$stringToSign
中的
0
内容长度替换为空字符串

从:

2015-02-21及更高版本中的内容长度标题

HTTP/2 403
content-length: 774
content-type: application/xml
server: Microsoft-HTTPAPI/2.0
x-ms-request-id: 98f7dbe2-801e-0017-78f2-b5d325000000
date: Wed, 07 Mar 2018 09:02:11 GMT

<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:98f7dbe2-801e-0017-78f2-b5d325000000
Time:2018-03-07T09:02:12.1896957Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'qaRQQPDc8T8lFCTq5W6ZkjrJoX6W+a419RMd8MWJsUg=' is not the same as any computed signature. Server used following string to sign: 'PUT











x-ms-date:Wed, 07 Mar 2018 09:02:11 GMT
x-ms-lease-action:acquire
x-ms-lease-duration:-1
x-ms-lease-id:49383176-ad23-4f85-acbf-01edcd02d177
x-ms-version:2017-04-17
/myaccount/mycontainer/myblob
comp:lease'.</AuthenticationErrorDetail></Error>
使用2015-02-21或更高版本时,如果内容长度为零, 然后将StringToSign的内容长度部分设置为空 绳子

更新:

进一步检查后,您的
$stringToSign
丢失
comp:lease
。请尝试更改以下代码行:

$stringToSign = array_merge($stringToSign, $headers, ["/$account/$container/$filename"]);


谢谢你的回复。我将
$stringToSign
的内容长度值修改为空字符串,但仍然不起作用:(我已经用我发现的另一个问题更新了我的答案。希望这能解决问题。如果没有,请编辑您的问题,并包括您计算的
$stringToSign
的值以及最新的错误消息,该消息显示Azure Storage计算的要签名的字符串。我相信您收到的错误是因为LUE不匹配。感谢您指出我的错误。但情况似乎仍然没有改变。因此,我更新了代码和错误响应。您可以编辑您的问题并包含由代码计算的stringToSign值吗?我发现的另一个问题是您的标题未排序。因此,您的标题应位于以下顺序:x-ms-date、x-ms-lease-action、x-ms-lease-duration、x-ms-lease-id和x-ms-version。请进行此更改并重试。
$stringToSign = array_merge($stringToSign, $headers, ["/$account/$container/$filename"]);
$stringToSign = array_merge($stringToSign, $headers, ["/$account/$container/$filename"], ["comp:lease"]);