gpt4 book ai didi

azure - 无法使用 Azure REST API 删除 Azure 存储表

转载 作者:行者123 更新时间:2023-12-03 01:49:09 25 4
gpt4 key购买 nike

我收到错误“服务器无法对请求进行身份验证。请确保授权 header 的值格式正确,包括签名。

我按照微软提供的授权教程,Delete Table , Authentication for the Azure Storage Services .

我错过了什么吗?

enter image description here

最佳答案

您似乎想要delete table via rest api .

DELETE https://myaccount.table.core.windows.net/Tables('mytable')

以下示例在我这边运行良好,请引用生成签名的代码。

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;
}

关于azure - 无法使用 Azure REST API 删除 Azure 存储表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41558785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com