Express github应用程序-webhook请求不';我没有有效载荷
首先,以下是我的github应用程序事件: 我设置了我的webhook URL(Express github应用程序-webhook请求不';我没有有效载荷,express,github-api,webhooks,Express,Github Api,Webhooks,首先,以下是我的github应用程序事件: 我设置了我的webhook URL(blahblah.com/watch)和express服务器,如下所示: const express = require("express"); const app = express(); app.post("/watch", (req, res) => { console.log(req); }); app.listen(3000, () => console.log("opened"
blahblah.com/watch
)和express服务器,如下所示:
const express = require("express");
const app = express();
app.post("/watch", (req, res) => {
console.log(req);
});
app.listen(3000, () => console.log("opened"));
app.post("/watch", (req, res) => {
let body = "";
req.on("readable", () => {
body += req.read();
});
req.on("end", () => {
console.log(body);
})
});
问题是,当我创建问题注释时,webhook的请求到达我的express服务器,但没有正文或有效负载
请求如下:
看那个!没有有效载荷!
我该怎么办?我做错了什么
我认为
req
必须有一个属性body
或payload
。如何访问请求的有效负载?事实上,问题不在于webhook请求,而在于我的express代码
我已通过如下方式修改代码解决了此问题:
const express = require("express");
const app = express();
app.post("/watch", (req, res) => {
console.log(req);
});
app.listen(3000, () => console.log("opened"));
app.post("/watch", (req, res) => {
let body = "";
req.on("readable", () => {
body += req.read();
});
req.on("end", () => {
console.log(body);
})
});
我不知道有readable
事件和end
事件来处理请求
我从中得到了一个想法。因为您使用的是Node,所以我建议您使用它来处理Webhook