【发布时间】:2018-05-02 15:22:23
【问题描述】:
我一整天都在调用 Azure 存储 REST API。响应显示这是由于 Azure 身份验证错误,但我不知道是什么问题。 你也可以在这里检查类似的问题
Authorization of Azure Storage service REST API
通过使用它,我得到了为我工作但不为桌子工作的血液。 如何用表格实现这一目标
var apiVersion = '2017-07-29';
var storageAccountName = "MyAccountName";
var key = "MyAccountKey";
var currentDate= new Date();
var strTime = currentDate.toUTCString();
var strToSign = 'GET\n\n\n\nx-ms-date:' + strTime + '\nx-ms-version:' + apiVersion + '\n/' + storageAccountName + '/?restype=service&comp=properties';
var secret = CryptoJS.enc.Base64.parse(key);
var hash = CryptoJS.HmacSHA256(strToSign, secret);
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
var auth = "SharedKeyLite " + storageAccountName + ":" + hashInBase64;
document.write(auth)
$.ajax({
type: "GET",
url: "https://MyAccountName.table.core.windows.net/?restype=service&comp=properties&sv=2017-07-29&ss=bqtf&srt=sco&sp=rwdlacup",
beforeSend: function (request) {
request.setRequestHeader("Authorization", auth);
request.setRequestHeader("x-ms-date", strTime);
request.setRequestHeader("x-ms-version", apiVersion);
},
processData: false,
success: function (msg) {
// Do something
},
error: function (xhr, status, error) {
// Handle error
}
});
sn-p 上面是访问 Azure 表存储。但是,这是行不通的。但是,如果我尝试对 blob 进行此操作,它似乎可以正常工作
var strToSign = 'GET\n\n\n\nx-ms-date:' + strTime + '\nx-ms-version:' + apiVersion + '\n/' + storageAccountName + '/?comp=list';
url: "https://appcrestdev.blob.core.windows.net/?comp=list",
【问题讨论】:
-
问题与链接中发布的内容类似,但针对“表”存储。
-
请分享您的代码。
-
正如 Gaurav 所说,请分享您的代码,以便其他人可以帮助您。另外,为什么不直接使用 Azure Storage Client Library 而不是自己编写认证代码呢?
-
更新问题
标签: azure azure-storage azure-table-storage azure-tablequery