2
votes

I had successfully retrieved Azure storage table details using the following code.

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;  

But when trying to get table list in a Storage account using the following REST API, exception occurred as "The remote server returned an error: (403) Forbidden."

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

I assumed that Canonicalized Resource should be different for this REST request and analyzed some Microsoft documentation, but cannot able to find any reference to construct it for list tables REST api.

Please help me in retrieving Azure Storage account tables list.

1

1 Answers

2
votes

Please change the following line of code:

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

to

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

Also, please note that your request URL will also change to https://storageaccount.table.core.windows.net/Tables.