简体   繁体   English

在C#WebAPI中的ApiController上以“传输编码:分块”方式提供数据

[英]Serving data with “transfer-encoding: chunked” on an ApiController in C#' WebAPI

I need to serve chunked transfer encoding data using an ApiController . 我需要使用ApiController提供分块的传输编码数据。 Because I do not have access to the HttpContext or the HttpRequest , I'm a bit lost as to where to write to the response and where to flush it. 因为我没有访问HttpContextHttpRequest的权限,所以我对在哪里写入响应以及在哪里刷新响应感到迷茫。

The setup looks like: 设置看起来像:

public class MyController : ApiController
{
   [Route("testing")]
   [HttpGet]
   public string Get()
   {
       ...
       return <response object ot HttpResponseMessage
   }
}

I guess I might be using the wrong base classes/framework/concept? 我想我可能使用了错误的基类/框架/概念? Thanks so much! 非常感谢!

You do have access to the Context and the Request. 确实有权访问上下文和请求。 You need access to the Response though: 但是,您需要访问响应:

public string Get()
{
    ActionContext.Response.Headers.TransferEncodingChunked = true;
    // ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM