asp.net-mvc – 使用ASP.NET MVC支持“Expect:100-continue”标头

我正在使用ASP.NET MVC实现一个REST API,并且以一个Post Body的请求的Expect:100-continue请求标头的形式出现了一个小小的绊脚石.

RFC 2616指出:

Upon receiving a request which
includes an Expect request-header
field with the “100-continue” expectation,an origin server MUST
either respond with 100 (Continue) status and continue to read
from the input stream,or respond with a final status code. The
origin server MUST NOT wait for the request body before sending
the 100 (Continue) response. If it responds with a final status
code,it MAY close the transport connection or it MAY continue
to read and discard the rest of the request. It MUST NOT
perform the requested method if it returns a final status code.

这听起来像我需要对请求作出两个响应,即它需要立即发送一个HTTP 100继续响应,然后继续从原始请求流(即HttpContext.Request.InputStream)读取,而不会终止请求,然后最终发送结果的状态码(为了参数,让我们说这是一个204无内容的结果).

所以问题是:

我正在阅读规范,我需要对请求做出两个答复?
>如何在ASP.NET MVC中完成?

w.r.t. (2)在继续阅读输入流之前,我已尝试使用以下代码

HttpContext.Response.StatusCode = 100;
HttpContext.Response.Flush();
HttpContext.Response.Clear();

…但是当我尝试设置最终的204状态代码时,我得到错误

System.Web.HttpException: Server cannot set status after HTTP headers have been sent.

解决方法

100-continue应该由IIS处理.是否有理由明确地做这个?

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....