【问题标题】:REST API in Windows AzureWindows Azure 中的 REST API
【发布时间】:2013-02-15 06:10:25
【问题描述】:

我正在尝试连接到 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);

?>

【问题讨论】:

    标签: php rest azure-storage


    【解决方案1】:

    如果您使用的是 PHP,为什么不使用 Windows Azure PHP SDK 来做呢? https://github.com/WindowsAzure/azure-sdk-for-php

    已经针对真实服务器进行了很好的测试。

    【讨论】:

    • SDK 不支持某些方法。实施这些的最佳方式是什么?
    • 你在谈论什么具体的 API,msft 希望你为这个 SDK 做出贡献。
    • 我是 azure 新手,azure php sdk 是否可用 REST Api 提供的所有功能。
    • 我认为是,至少大部分情况下
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    相关资源
    最近更新 更多