Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在HTTP请求中找到的MAC签名与使用php的任何计算签名azure集成不同_Php_Azure_Azure Storage Blobs - Fatal编程技术网

在HTTP请求中找到的MAC签名与使用php的任何计算签名azure集成不同

在HTTP请求中找到的MAC签名与使用php的任何计算签名azure集成不同,php,azure,azure-storage-blobs,Php,Azure,Azure Storage Blobs,我正在尝试使用azure rest API列出blob。我正在使用下面的代码列出使用curl和php的blob,看起来生成的auth签名是错误的。有人能帮我解决授权问题吗 $date = gmdate('D, d M Y H:i:s \G\M\T'); $account_name = "xyz"; $containername = "abc"; $account_key = "asdf"; $stringtosign = "GET\n\n\n$date\n/$account_name/$con

我正在尝试使用azure rest API列出blob。我正在使用下面的代码列出使用curl和php的blob,看起来生成的auth签名是错误的。有人能帮我解决授权问题吗

$date = gmdate('D, d M Y H:i:s \G\M\T');
$account_name = "xyz";
$containername = "abc";
$account_key = "asdf";

$stringtosign = "GET\n\n\n$date\n/$account_name/$containername()";
$signature = 'SharedKey'.' '.$account_name.':'.base64_encode(hash_hmac('sha256', $stringtosign, base64_decode($account_key),true));

$endpoint = 'https://'.$account_name.'.blob.core.windows.net';
$url = $endpoint.'/'.$containername.'?restype=container&comp=list'; 

$headers = [
    "x-ms-date:{$date}",
    'x-ms-version:2014-02-14',
    'Accept:application/json;odata=nometadata',
    "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);

我已将您的代码更改为以下内容,然后使其正常工作


我已将您的代码更改为以下内容,然后使其正常工作


它可以工作!。。从过去两天开始,我一直在努力修复它。非常感谢,我尝试了代码,但仍然得到相同的错误。有什么想法吗?这很有效!。。从过去两天开始,我一直在努力修复它。非常感谢,我尝试了代码,但仍然得到相同的错误。有什么想法吗?
AuthenticationFailedServer failed to authenticate the request. Make sure the 

value of Authorization header is formed correctly including the signature.
RequestId:sdf4b5-0341-043559-2sdf53-b3sdf000
Time:2017-04-12T06:10:18.8696178ZThe MAC signature found in the HTTP request 'sfdf98i8p7f1QiJwszds' is not the same as any computed signature. Server used following string to sign: 'GET
x-ms-date:Wed, 12 Apr 2017 06:10:17 GMT
x-ms-version:2014-02-14
/abc/xyz
comp:list
restype:container'.
<?php

$date = gmdate('D, d M Y H:i:s \G\M\T');
$account_name = "xyz";
$containername = "abc";
$account_key = "asdf";

$canonicalizedHeaders  = "x-ms-date:$date\nx-ms-version:2014-02-14";
$canonicalizedResource = "/$account_name/$containername\ncomp:list\nrestype:container";

$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';
$url = $endpoint.'/'.$containername.'?restype=container&comp=list'; 

$headers = [
    "x-ms-date:{$date}",
    'x-ms-version:2014-02-14',
    'Accept:application/json;odata=nometadata',
    "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);