我正在开发 azure rest API,以使用 PHP 获取页面范围。我正在关注其余的 API 文档 here
我无法验证它所说的其余 API
The MAC signature found in the HTTP request '6fsdfhyuiz78' is not the same as any computed signature. Server used following string to sign GET
我使用下面的代码来获取页面范围。在传递请求 header 以生成用于签署身份验证签名的字符串时,我在这里错过了一些内容。如果有人能帮助我解决这个问题,那就太好了。
$date = gmdate('D, d M Y H:i:s \G\M\T');
$account_name = "account name";
$containername = "container name";
$blob = "blobname.vhd";
$mypremiumdisk_ss1 = "2017-09-12V09:15:43.00001Z";
$mypremiumdisk_ss2 = "2017-09-12V09:55:47.00002Z";
$account_key = "account key";
$canonicalizedHeaders = "x-ms-date:$date\nx-ms-version:2015-07-08";
$canonicalizedResource = "/$account_name/$containername/$blob\ncomp:pagelist\nsnapshot:$mypremiumdisk_ss1\nprevsnapshot:$mypremiumdisk_ss2";
$arraysign = array();
$arraysign[] = 'GET'; /*HTTP Verb*/
$arraysign[] = ''; /*Content-Encoding*/
$arraysign[] = ''; /*Content-Language*/
$arraysign[] = ''; /*Content-Length (include value when zero)*/
$arraysign[] = ''; /*Content-MD5*/
$arraysign[] = ''; /*Content-Type*/
$arraysign[] = ''; /*Date*/
$arraysign[] = ''; /*If-Modified-Since */
$arraysign[] = ''; /*If-Match*/
$arraysign[] = ''; /*If-None-Match*/
$arraysign[] = ''; /*If-Unmodified-Since*/
$arraysign[] = ''; /*Range*/
$arraysign[] = $canonicalizedHeaders; /*CanonicalizedHeaders*/
$arraysign[] = $canonicalizedResource; /*CanonicalizedResource*/
$stringtosign = implode("\n", $arraysign);
$signature = 'SharedKey'.' '.$account_name.':'.base64_encode(hash_hmac('sha256', $stringtosign, base64_decode($account_key), true));
$endpoint = 'https://'.$account_name.'.blob.core.windows.net';
echo $url = $endpoint.'/'.$containername.'/'.$blob.'?comp=pagelist&snapshot='.$mypremiumdisk_ss1.'&prevsnapshot='.$mypremiumdisk_ss2;
$headers = [
"x-ms-date:{$date}",
'x-ms-version:2015-07-08',
'Accept:application/json;odata=nometadata',
'Accept-Charset:UTF-8',
"Authorization:{$signature}"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
echo '<pre>';print_r($response);
最佳答案
我注意到的一些事情:
$mypremiumdisk_ss1 = "2017-09-12V09:15:43.00001Z";
$mypremiumdisk_ss2 = "2017-09-12V09:55:47.00002Z";
请将日期/时间值中的V
更改为T
。
$canonicalizedResource = "/$account_name/$containername/$blob\ncomp:pagelist\nsnapshot:$mypremiumdisk_ss1\nprevsnapshot:$mypremiumdisk_ss2";
基于documentation
, canonicalizedResource
应包含按字母顺序排序的查询参数。请将以上行更改为:
$canonicalizedResource = "/$account_name/$containername/$blob\ncomp:pagelist\nprevsnapshot:$mypremiumdisk_ss2\nsnapshot:$mypremiumdisk_ss1";
关于php - AuthenticationFailedServer 无法对 azure 中的请求进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46196352/