无法使用Azure REST API删除Azure存储表 [英] Can't delete Azure Storage Table using Azure REST API
问题描述
我收到错误消息"服务器无法验证请求.请确保正确形成包括签名的授权标头的值."
我遵循了Microsoft提供的授权教程,删除表,
I followed the authorization tutorial provided by Microsoft, Delete Table, Authentication for the Azure Storage Services.
我错过了什么吗?
推荐答案
似乎您想
删除 https://myaccount.table.core.windows.net/Tables('mytable')
DELETE https://myaccount.table.core.windows.net/Tables('mytable') 以下示例对我而言效果很好,请参考代码以生成签名. the following sample works fine on my side, please refer to the code to generate the signature. 这篇关于无法使用Azure REST API删除Azure存储表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
string StorageAccount = "account name here";
string StorageKey = "account key here";
string tablename = "table name";
string requestMethod = "DELETE";
string mxdate = "";
string storageServiceVersion = "2015-12-11";
protected void Button1_Click(object sender, EventArgs e)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(string.Format(CultureInfo.InvariantCulture,
"https://{0}.table.core.windows.net/Tables('{1}')",
StorageAccount, tablename));
req.Method = requestMethod;
//specify request header
string AuthorizationHeader = generateAuthorizationHeader();
req.Headers.Add("Authorization", AuthorizationHeader);
req.Headers.Add("x-ms-date", mxdate);
req.Headers.Add("x-ms-version", storageServiceVersion);
req.ContentType = "application/json";
req.Accept = "application/json;odata=minimalmetadata";
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
}
}
public string generateAuthorizationHeader()
{
mxdate = DateTime.UtcNow.ToString("R");
string canonicalizedResource = $"/{StorageAccount}/Tables('{tablename}')";
string contentType = "application/json";
string stringToSign = $"{requestMethod}\n\n{contentType}\n{mxdate}\n{canonicalizedResource}";
HMACSHA256 hmac = new HMACSHA256(Convert.FromBase64String(StorageKey));
string signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)));
String authorization = String.Format("{0} {1}:{2}",
"SharedKey",
StorageAccount,
signature
);
return authorization;
}