规范化资源以列出 Azure 存储表
Canonicalized Resource to list Azure storage tables
我已使用以下代码成功检索到 Azure 存储 table 详细信息。
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 获取存储帐户中的 table 列表时,出现异常“远程服务器返回错误:(403) 禁止访问."
https://myaccount.table.core.windows.net/Tables
我假设规范化资源对于此 REST 请求应该不同并分析了一些 Microsoft 文档,但无法找到任何参考来为列表 tables REST api.
请帮助我检索 Azure 存储帐户 tables 列表。
请更改以下代码行:
string stringToSign = date + "\n/" + storageAccount + "/" + tableName;
至
string stringToSign = date + "\n/" + storageAccount + "/Tables";
另请注意,您的请求 URL 也将更改为 https://storageaccount.table.core.windows.net/Tables
。
我已使用以下代码成功检索到 Azure 存储 table 详细信息。
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 获取存储帐户中的 table 列表时,出现异常“远程服务器返回错误:(403) 禁止访问."
https://myaccount.table.core.windows.net/Tables
我假设规范化资源对于此 REST 请求应该不同并分析了一些 Microsoft 文档,但无法找到任何参考来为列表 tables REST api.
请帮助我检索 Azure 存储帐户 tables 列表。
请更改以下代码行:
string stringToSign = date + "\n/" + storageAccount + "/" + tableName;
至
string stringToSign = date + "\n/" + storageAccount + "/Tables";
另请注意,您的请求 URL 也将更改为 https://storageaccount.table.core.windows.net/Tables
。