node.js - 从节点 JS 执行 POST 时无法验证第一个证书错误
问题描述
我正在尝试对需要签名的 REST 端点进行 POST。请在下面找到代码片段
var express = require("express");
var bodyParser = require("body-parser");
var crypto = require('crypto');
var request = require('request');
const APPLICATION_JSON_UTF8 = 'application/json; charset=utf-8';
const SIGNATURE = 'X-Hub-Signature';
const CONTENT_TYPE = 'Content-Type';
const botConfig = {
webhookURL: 'https://8c9a9e46.ngrok.io/myURL',
secretKey: 'SecretKey'
};
var app = express();
app.listen(3000, function () {
console.log("app running on port.");
});
function buildSignatureHeader(buf, secret) {
return 'sha256=' + buildSignature(buf, secret);
}
function buildSignature(buf, secret) {
const hmac = crypto.createHmac('sha256', Buffer.from(secret, 'utf8'));
hmac.update(buf);
return hmac.digest('hex');
}
app.get('/', function (req, res) {
const recvMessage = {
"userId":"2211333",
"messagePayload": {
"type":"Pony",
"text": "Hi There",
"channelName":"channelName"
},
"profile": {"firstName": 'bibin'}
};
const data = Buffer.from(JSON.stringify(recvMessage), 'utf8');
const headers = {};
headers[CONTENT_TYPE] = APPLICATION_JSON_UTF8;
headers[SIGNATURE] = buildSignatureHeader(data, botConfig.secretKey);
var interactive = false;
var oauth=false;
console.log(buildSignatureHeader(data, botConfig.secretKey));
request.post({
uri: botConfig.webhookURL,
headers: headers,
body: data
},function(error, response, body){
console.log(body);
console.log('error'+error);
console.log('response'+response);
});
});
现在,当我点击节点 JS 服务器时,我收到一个异常,上面写着“无法验证第一个证书”。我尝试在 npm 全局级别设置代理,但问题仍然存在。有没有人看到这个问题?有人可以给我一些指示吗?
解决方案
推荐阅读
- spring-boot - Spring Boot 未加载 bootstrap.properties 文件
- python - 使用 float() 转换的表达式评估错误
- android - QT Android - GDB 进程意外终止(退出代码 0)
- react-native - 如何左对齐第一个元素并将其余元素居中在“react-native-snap-carousel”中
- pine-script - 是否可以从“安全”功能中获取嵌套元组?
- java - StringTokenizer 中的意外结果
- javascript - 带有 typescript 和 axios 的 useFetch 钩子
- javascript - 如何使用数据库中的事件最好地填充日历
- python - 从大型图像数据集中删除重复项
- airflow - 在一个 dag 上多次循环执行许多气流任务