利用“传输编码:分块"来服务数据.在C#WebAPI中的ApiController上 [英] Serving data with "transfer-encoding: chunked" on an ApiController in C#' WebAPI

查看:60
本文介绍了利用“传输编码:分块"来服务数据.在C#WebAPI中的ApiController上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 ApiController 提供分块传输编码数据.因为我无权访问 HttpContext HttpRequest ,所以我对在哪里写入响应以及在何处刷新响应感到迷茫.

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.

设置如下:

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

这篇关于利用“传输编码:分块"来服务数据.在C#WebAPI中的ApiController上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆