【发布时间】:2015-03-01 01:25:24
【问题描述】:
我正在将 HTTP 请求正文中的数据发送到内容编码为 gzip 的 Restify 实例。唯一的问题是我无法访问包含压缩数据的正文。
这是我用来确定它的 JS 代码,但 req.body 显示为未定义:
server.use(function(req, res, next) {
if(req.headers['content-encoding'] == 'gzip')
{
console.log(req);
// We have a gzipped body here
var zlib = require("zlib");
var gunzip = zlib.createGunzip();
console.log("Body: "+ req.body)
console.log("Length: " + req.body.length);
}
else
{
apiKey = req.query['apiKey'];
authenticateAndRoute(apiKey, req, res, next)
}
})
有人知道如何在此处访问 req.body 或等效的吗?
【问题讨论】:
标签: node.js http http-headers restify