c# - 如何在 HttpResponseMessage 上设置内容编码

标签 c# asp.net-web-api encoding httpresponse

我想在 HttpResponseMessage 上设置 Content-Encoding,但我终究无法找到方法。鉴于此 WebApi 操作

public HttpResponseMessage Get()
{
    byte[] tile = GetTile();

    var result = new HttpResponseMessage(HttpStatusCode.OK) {Content = new ByteArrayContent(tile)};

    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-protobuf");

    return result;
}

如何将 header 上的内容编码设置为 gzip?

 result.Content.Headers.ContentEncoding

只读。

最佳答案

ContentEncoding 属性是 ICollection 的一个实例.

这提供了 .Add().Clear() 方法来控制内容。

关于c# - 如何在 HttpResponseMessage 上设置内容编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42072930/

相关文章:

c# - 扩展 ASP.net HelpPage 主页

c# - HttpControllerSelector 不适用于属性路由

asp.net-mvc - AngularJS + ASP.NET Web API + ASP.NET MVC身份验证

.net - Web API 接口(interface)在本地工作,但在部署到 Azure 网站后得到 404

C# + 单声道 : Error while running Azure-Storage SDK

c# - Process.Start 很慢

javascript - Html.CheckBoxFor 的 JQuery Validate 和 C# ASP MVC 问题

html - Perl 编码 - 将文件保存为 UTF8

encoding - "encoding-agnostic"的定义是什么?

java - 编码控制台俄语 sumbols 输入