如何在 webApi 当中接收 Gzip 压缩或者加密后的 请求消息内容
1个回答
展开全部
重写 :DelegatingHandler抽象类
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
Stream stream = request.Content.ReadAsStreamAsync().Result;
Encoding encoding = Encoding.UTF8;
stream.Position = 0;
request.Content = new StreamContent(new GZipStream(stream, CompressionMode.Decompress));
request.Content.Headers.Remove("Content-Type");
request.Content.Headers.Add("Content-encoding", "gzip");
request.Content.Headers.Add("Content-Type", "application/json;charset=UTF-8");
return base.SendAsync(request, cancellationToken);
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
Stream stream = request.Content.ReadAsStreamAsync().Result;
Encoding encoding = Encoding.UTF8;
stream.Position = 0;
request.Content = new StreamContent(new GZipStream(stream, CompressionMode.Decompress));
request.Content.Headers.Remove("Content-Type");
request.Content.Headers.Add("Content-encoding", "gzip");
request.Content.Headers.Add("Content-Type", "application/json;charset=UTF-8");
return base.SendAsync(request, cancellationToken);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询