小编Jor*_*ins的帖子

从Web API控制器重定向POST请求时,处理100-继续

我有一个ApiController响应POST请求,通过HTTP的状态码307重定向它.它只使用标题中的信息,因此此操作不需要请求的主体.此操作相当于:

public HttpResponseMessage Post() {
    var url;
    // Some logic to construct the URL
    var response = new HttpResponseMessage(HttpStatusCode.TemporaryRedirect);
    response.Headers.Location = new System.Uri(url);
    return response;
}
Run Code Online (Sandbox Code Playgroud)

这很简单,但我想做一个改进.请求正文可能包含大量数据,因此我想利用HTTP状态代码100来提高此请求的效率.使用现在的控制器,对话可能如下所示:

> POST /api/test HTTP/1.1
> Expect: 100-continue
> ...

< HTTP/1.1 100 Continue

> (request body is sent)

< HTTP/1.1 307 Temporary Redirect
< Location: (the URL)
< ...
Run Code Online (Sandbox Code Playgroud)

由于重定向操作不需要请求主体,我希望能够将会话缩短为:

> POST /api/controller HTTP/1.1
> Expect: 100-continue
> ...

< HTTP/1.1 307 Temporary Redirect
< Location: (the URL)
< ...
Run Code Online (Sandbox Code Playgroud)

我花了一天的时间来研究如何实现这一目标,但我还没有找到解决方案.在我的研究中,我学到了: …

c# asp.net iis http-status-code-100 asp.net-web-api2

5
推荐指数
1
解决办法
1953
查看次数