我已使用以下代码成功检索了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存储帐户表列表。
答案 0 :(得分:2)
请更改以下代码行:
string stringToSign = date + "\n/" + storageAccount + "/" + tableName;
到
string stringToSign = date + "\n/" + storageAccount + "/Tables";
此外,请注意,您的请求网址也将更改为https://storageaccount.table.core.windows.net/Tables
。