简体   繁体   中英

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

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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