//以下代码参考文档 https://cloud.tencent.com/document/product/628/11819
//secretId,secretKey出于安全考虑做了替换,实际应用场景中为真实值
//请问这样的请求方式有什么问题吗?实际使用中总是返回401
const axios = require('axios');
const HmacSha1 = require('crypto-js/hmac-sha1.js');
const Base64 = require('crypto-js/enc-base64.js');
const nowDateUTC = (new Date()).toUTCString();// Jan, 01 May 2020 00:00:00 GMT
const signing_str = `date: ${nowDateUTC}`;// 签名内容
const secretId = 'my secretId';// 实际应用场景中作替换
const secretKey = 'my secretKey';// 实际应用场景中作替换
const signature = Base64.stringify((HmacSha1(signing_str, secretKey)));// Base64下加密后的签名
axios.post('https://www.example.com/release/example', {}, {
headers: {
'Date': nowDateUTC,
'Authorization': `hmac id="${secretId}", algorithm="hmac-sha1", headers="date ",signature="${signature}"`
}
})
相似问题