首页 > 解决方案 > 规范化资源以列出 Azure 存储表

问题描述

我已使用以下代码成功检索 Azure 存储表详细信息。

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://" + storageAccountName + ".table.core.windows.net/" + tableName;);
request.Method = "GET";
request.Accept = "application/json";
var date = DateTime.UtcNow.ToString("R", System.Globalization.CultureInfo.InvariantCulture);
request.Headers["x-ms-date"] = date;
request.Headers["x-ms-version"] = "2015-04-05";
string stringToSign = date + "\n/" + storageAccount + "/" + tableName; //Canonicalized Resource
System.Security.Cryptography.HMACSHA256 hasher = new System.Security.Cryptography.HMACSHA256(Convert.FromBase64String("accessKey"));
string strAuthorization = "SharedKeyLite " + storageAccountName + ":" + System.Convert.ToBase64String(hasher.ComputeHash(System.Text.Encoding.UTF8.GetBytes(stringToSign)));
request.Headers["Authorization"] = strAuthorization;
Task<WebResponse> response = request.GetResponseAsync();
HttpWebResponse responseresult = (HttpWebResponse)response.Result;  

但是当尝试使用以下 REST API 获取存储帐户中的表列表时,发生异常为“远程服务器返回错误:(403)禁止。

https://myaccount.table.core.windows.net/Tables

我假设此 REST 请求的规范化资源应该不同,并分析了一些 Microsoft 文档,但无法找到任何参考来为列表表 REST api 构造它。

请帮助我检索 Azure 存储帐户表列表。

标签: azureazure-storageazure-table-storage

解决方案


请更改以下代码行:

string stringToSign = date + "\n/" + storageAccount + "/" + tableName;

string stringToSign = date + "\n/" + storageAccount + "/Tables";

另外,请注意,您的请求 URL 也将更改为https://storageaccount.table.core.windows.net/Tables.


推荐阅读