我已使用以下代码成功检索到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文档,但无法找到任何引用来为列表表RESTapi构建它。
请帮助我检索Azure存储帐户表列表。
请更改以下代码行:
string stringToSign = date + "n/" + storageAccount + "/" + tableName;
至
string stringToSign = date + "n/" + storageAccount + "/Tables";
此外,请注意,您的请求URL也将更改为https://storageaccount.table.core.windows.net/Tables
。