如何使用Postman将消息发布到Azure队列存储



我需要在Postman应用程序中完成这一切。我发现了使用blob和表的示例,但它们似乎不适合队列存储。我认为最大的问题是我无法正确创建签名部分。

我相信我成功地在poster中执行了Get Message,但我得到了";服务器无法对请求进行身份验证"Post请求时出错。我试图发布的消息是XML格式的,并使用与Get相同的预请求脚本。

发布和获取请求的预请求脚本(从在线来源复制(:

const storageAccount = pm.variables.get('azure_storage_account');
const accountKey = pm.variables.get('azure_storage_key');
pm.variables.set("header_date", new Date().toUTCString());
// Get hash of all header-name:value
const headers = pm.request.getHeaders({ ignoreCase: true, enabled: true });
// Construct Signature value for Authorization header
var signatureParts = [
pm.request.method.toUpperCase(),
headers["content-encoding"] || "",
headers["content-language"] || "",
headers["content-length"]  || "",
//    pm.request.body ? pm.request.body.toString().length || "" : "",
headers["content-md5"] || "",
headers["content-type"] || "",
headers["x-ms-date"] ? "" : (pm.variables.get("header_date") || ""),
headers["if-modified-since"] || "",
headers["if-match"] || "",
headers["if-none-match"] || "",
headers["if-unmodified-since"] || "",
headers["range"] || ""
];
// Construct CanonicalizedHeaders
const canonicalHeaderNames = [];
Object.keys(headers).forEach(key => {
if (key.startsWith("x-ms-")) {
canonicalHeaderNames.push(key);
}
});
// Sort headers lexographically by name
canonicalHeaderNames.sort();
const canonicalHeaderParts = [];
canonicalHeaderNames.forEach(key => {
let value = pm.request.getHeaders({ ignoreCase: true, enabled: true })[key];
// Populate variables
value = pm.variables.replaceIn(value);
// Replace whitespace in value but not if its within quotes
if (!value.startsWith(""")) {
value = value.replace(/s+/, " ");
}
canonicalHeaderParts.push(`${key}:${value}`);
});
// Add headers to signature
signatureParts.push.apply(signatureParts, canonicalHeaderParts);
// Construct CanonicalizedResource
const canonicalResourceParts = [
`/${pm.variables.get("azure_storage_account")}${pm.request.url.getPath()}`
];
const canonicalQueryNames = [];
pm.request.url.query.each(query => {
canonicalQueryNames.push(query.key.toLowerCase());
});
canonicalQueryNames.sort();
canonicalQueryNames.forEach(queryName => {
const value = pm.request.url.query.get(queryName);
// NOTE: This does not properly explode multiple same query params' values
// and turn them into comma-separated list
canonicalResourceParts.push(`${queryName}:${value}`);
});
// Add resource to signature
signatureParts.push.apply(signatureParts, canonicalResourceParts);
console.log("Signature Parts", signatureParts);
// Now, construct signature raw string
const signatureRaw = signatureParts.join("n");
console.log("Signature String", JSON.stringify(signatureRaw));
// Hash it using HMAC-SHA256 and then encode using base64
const storageKey = pm.variables.get("azure_storage_key");
const signatureBytes = CryptoJS.HmacSHA256(signatureRaw, CryptoJS.enc.Base64.parse(storageKey));
const signatureEncoded = signatureBytes.toString(CryptoJS.enc.Base64);
console.log("Storage Account", pm.variables.get("azure_storage_account"));
console.log("Storage Key", storageKey);

// Finally, make it available for headers
pm.variables.set("header_authorization",
`SharedKey ${pm.variables.get("azure_storage_account")}:${signatureEncoded}`);

邮差中的邮件头:请求的头和URI

有没有人有工作的例子,或者知道从这里搬到哪里?

编辑:添加控制台和错误图像:

为安全审查控制台输出

为安全审查错误输出

正如您所说,Get-And运行良好,如果使用SAS,可能是权限问题。请确保存储队列参与者对存储队列的权限。

如果使用SAS:,可能有许多原因导致此错误

  1. 检查您是否没有足够的SAS权限。检查您是否标记了读、写、列表权限。或者尝试生成新的SAS密钥
  2. 以编程方式访问请求时,请确保该请求不包含任何空标头。如果特定标头的值为空(或null(,则应将该标头从请求中排除
  3. 此外,如果以上不是原因,请尝试升级sdk的版本4.请检查编码是否正确,例如:UTF-8

使用共享密钥身份验证通过REST API c#查看Azure存储队列-堆栈溢出

参考文献:

  1. c#-在HTTP请求"中找到的MAC签名不是与任何计算签名相同。服务器将以下字符串用于sign:'PUT-堆栈溢出
  2. 使用共享密钥授权(REST API(-Azure存储| Microsoft文档
  3. rest-在HTTP请求"…"中找到的MAC签名不是与任何计算签名相同-堆栈溢出

最新更新