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

谁说胖子不能爱 提交于 2019-12-11 11:58:45

问题


I need to serve chunked transfer encoding data using an 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.

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!


回答1:


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;
    // ...
}


来源:https://stackoverflow.com/questions/31388424/serving-data-with-transfer-encoding-chunked-on-an-apicontroller-in-c-webapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!