支持"预期:100-继续]使用ASP.NET MVC头部 [英] Supporting the "Expect: 100-continue" header with ASP.NET MVC

查看:189
本文介绍了支持"预期:100-继续]使用ASP.NET MVC头部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施使用ASP.NET MVC一个REST API,和一个小的绊脚石已经拿出了期望的形式:100-继续请求标头请求与后机身。

RFC 2616 指出:


  

一旦接收到请求该
  包括预期要求标头
          与100-继续期望,原始服务器MUST场
          无论是与100(继续)响应状态,并继续阅读
          从输入流,或具有最终状态code响应。该
          起源服务器不能等待请求体发送前
          100(继续)响应。如果它最终状态响应
          code,它可能会关闭传输连接或它可能继续
          读取并丢弃请求的其余部分。它不能
          执行请求的方法,如果它返回一个最终状态code。


这听起来好像我需要做的两个应用于请求响应,即它需要立即发送一个HTTP 100继续响应,然后继续从原来的请求流中读取(即 HttpContext.Request.InputStream )没有结束请求,最后发送产生的状态code(对于参数的缘故,可以说这是一个204无内容结果)。

所以,问题是:


  1. 我是阅读说明书正确的,我需要做两个响应的请求?

  2. 这怎么在ASP.NET MVC中?
  3. 完成

w.r.t。 (2)我已经尝试使用以下code继续读取输入流之前试过...

  HttpContext.Response.Status code = 100;
HttpContext.Response.Flush();
HttpContext.Response.Clear();

...但是当我尝试设置最后的204状态code我得到的错误:


  

System.Web.HttpException:后HTTP标头已被送往服务器不能设置状态



解决方案

100-继续应该由IIS处理。是否有你为什么要这么做的理由明确?

I'm implementing a REST API using ASP.NET MVC, and a little stumbling block has come up in the form of the Expect: 100-continue request header for requests with a post body.

RFC 2616 states that:

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.

This sounds to me like I need to make two responses to the request, i.e. it needs to immediately send a HTTP 100 Continue response, and then continue reading from the original request stream (i.e. HttpContext.Request.InputStream) without ending the request, and then finally sending the resultant status code (for the sake of argument, lets say it's a 204 No Content result).

So, questions are:

  1. Am I reading the specification right, that I need to make two responses to a request?
  2. How can this be done in ASP.NET MVC?

w.r.t. (2) I have tried using the following code before proceeding to read the input stream...

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

...but when I try to set the final 204 status code I get the error:

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

解决方案

100-continue should be handled by IIS. Is there a reason why you want to do this explicitly?

这篇关于支持"预期:100-继续]使用ASP.NET MVC头部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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