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

前端之家收集整理的这篇文章主要介绍了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处理.是否有理由明确地做这个?

猜你在找的asp.Net相关文章