我正在尝试连接到 Windows Azure REST API,但总是遇到这样的问题:
The MAC signature found in the HTTP request '...' is not the same as any computed signature.
我无法获得正确的签名。我还尝试了 Objective-C 和 Windows Azure REST API 的不同方法,但总是得到相同的错误。PHP上有完整的清单:
function send_request($url, $headers)
{
if ($curl = curl_init())
{
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
return curl_exec($curl);
curl_close($curl);
}
return false;
}
function encode_string_to_sign($string_to_sign, $key)
{
$hash = hash_hmac("sha256", $string_to_sign, $key, true);
$signature = base64_encode($hash);
return $signature;
}
header("Content-Type: application/xhtml+xml");
// GET Container Metadata
$url = "http://snip.blob.core.windows.net/elements?restype=container&comp=metadata";
$access_key_1 = "...";
$access_key_2 = "...";
$current_date = "Thu, 28 Feb 2013 21:10:00 GMT";
$canonicalized_headers = "x-ms-date:$current_date\nx-ms-version:2009-09-19";
$canonicalized_resource = "/snip/elements\ncomp:metadata\nrestype:container";
$string_to_sign = "GET\n\n\n\n\n\n\n\n\n\n\n\n" . $canonicalized_headers . "\n" . $canonicalized_resource;
$signature = utf8_encode(encode_string_to_sign($string_to_sign, $access_key_1));
$headers = array("Authorization: SharedKey snip:" . $signature, "x-ms-date: " . $current_date, "x-ms-version: 2009-09-19");
echo send_request($url, $headers);
?>