本文介绍了无法使用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存储表
发布评论