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

编程入门 行业动态 更新时间:2024-10-28 10:23:04
本文介绍了无法使用Azure REST API删除Azure存储表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我收到错误消息"服务器无法验证请求.请确保正确形成包括签名的授权标头的值."

我遵循了Microsoft提供的授权教程,删除表, Azure存储服务的身份验证.

I followed the authorization tutorial provided by Microsoft, Delete Table, Authentication for the Azure Storage Services.

我错过了什么吗?

推荐答案

似乎您想通过rest api删除表.

删除 myaccount.table.core.windows/Tables('mytable')

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

以下示例对我而言效果很好,请参考代码以生成签名.

the following sample works fine on my side, please refer to the code to generate the signature.

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, "{0}.table.core.windows/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 REST API删除Azure存储表

本文发布于:2023-10-07 10:21:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469124.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Azure   REST   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!