加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 20:19:27 所属栏目:asp.Net 来源:网络整理
导读:我正在使用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” expe
我正在使用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处理.是否有理由明确地做这个?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读