我有带有 Http 触发器的 nodejs azure 函数。我正在使用 POST 方法并将正文发送到 azure 函数。由于正文较大,因此使用 gzip 进行压缩。
我在 azure 函数中收到请求,内容编码 header 是“gzip”。我尝试使用nodejs
zlib.gunzip(req.body,...)
它抛出了一个错误
Error: incorrect header check
最佳答案
对于 JavaScript 函数,streaming is not supported Functions 运行时提供请求正文而不是请求对象。对于 C# 函数没有特殊处理,因此您可以尝试使用 C# 函数。
这里有一个C#函数,用于解压缩gzip请求体供您引用。
using System.Net;
using System.IO.Compression;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
var inputStream = await req.Content.ReadAsStreamAsync();
string decompressedReqBody = string.Empty;
using (GZipStream decompressionStream = new GZipStream(inputStream, CompressionMode.Decompress))
{
using (StreamReader sr = new StreamReader(decompressionStream))
{
decompressedReqBody = sr.ReadToEnd();
log.Info(decompressedReqBody);
}
}
return req.CreateResponse(HttpStatusCode.OK, decompressedReqBody);
}
关于node.js - Azure 函数压缩 POST 正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45887481/