![](/img/trans.png)
[英]How to use postman to request an API that is protected with devise?
[英]HMAC protected API and Postman request
我正在嘗試針對受 HMAC 保護的 API 發出請求。
我可以使用 HTTPie 的 HMAC auth 插件成功發送請求,如下所示:
http --auth-type=hmackey --auth="key1:secret1" api_url
但是,通過 Postman 發出請求,我沒有取得任何成功。 我正在關注下面的鏈接,該鏈接解釋了如何使用預請求腳本,但我總是收到 401:
https://github.com/acquia/http-hmac-postman
有什么想法嗎?
如果要為 post 請求創建一個 hmac 並將其設置為 header,只需在 pre-request 腳本中使用如下 cryptoJs。
const secret = 'your_secret';
var hash = CryptoJS.HmacSHA256(pm.request.body.toString(), secret);
var hashBase64 = CryptoJS.enc.Base64.stringify(hash);
console.log(hashBase64);
//set it to the environment variable
pm.environment.set("HmacContentSha", "hashBase64");
環境變量HmacContentSha
需要傳入請求 header。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.