我一整天都在调用 Azure Storage REST API。响应显示这是由于 Azure 身份验证中的错误,但我不知道是什么问题。你也可以在这里检查类似的问题
通过使用它,我得到了为我工作但不是为桌子工作的血液。如何用表实现这一点
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
}
});
上面的代码片段是访问 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",