gpt4 book ai didi

asp.net - IISExpress 10 不会通过 HTTPS 返回原因短语

转载 作者:行者123 更新时间:2023-12-02 15:19:08 25 4
gpt4 key购买 nike

在 IISExpress 10 和 VS2015 Web API Controller 中使用 HTTPS 时,不会发回 HttpResponseMessage 的 ReasonPhrase。如果我通过 HTTP 连接,它工作正常,但 HTTPS 只会清除原因短语。当部署到 azure 时,这种情况不会发生(https 按预期工作),它只发生在我的本地计算机上。

您可以通过制作一个具有 Web API 支持的新 MVC 应用程序(框架 4.5.2)来重现此情况。创建一个新的 Web api Controller (它将使用 mvc Controller 和 HttpStatusCodeResult 执行相同的操作)并添加一个 post 命令,例如:

public HttpResponseMessage Post()
{
var ret = new HttpResponseMessage((HttpStatusCode)270) { ReasonPhrase = "Test reason phrase", Content = new StringContent("test content") };
return ret;
}

我用 postman 来测试它。通过 http,状态将为

270 Test reason phrase

通过 HTTPS 就可以了

270 OK

您可以设置一个断点,并查看 ret 是否设置正确,无论请求来自何处,因此 IIS 中的某些内容会覆盖 HTTPS 上的 ReasonPhrase。

我尝试将 web.config 中的 httpErrors 设置为 errorMode 和现有响应的几乎所有组合。我的 machine.config(适用于任何版本的 .net)未设置为零售。 .vs 内的 application.config 将 httpErrors 设置为 overrideModeDefault="Allow"。

我想不出也找不到任何其他要修改设置的建议。这只是 iisexpress 的错误/限制吗?还是我缺少一些神奇的设置?

更新:

我用Windows 10和VS2015制作了一个VM来测试。结果相同。我还在虚拟机上启用了 IIS(普通 IIS)并发布到它。也有相同的结果。

我还只是为了好玩而将状态代码更改为 570,这给出了相同的结果,“570 OK”,我觉得这很有趣,因为 5xx 不被视为成功代码,所以我预计会出现与 OK 不同的结果。

最佳答案

我遇到了同样的问题,看起来是由于 IIS 10.0 使用 HTTP/2 以及您的浏览器造成的,这不允许使用 ReasonPhrase 字段。

https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2.4

8.1.2.4. Response Pseudo-Header Fields

For HTTP/2 responses, a single ":status" pseudo-header field isdefined that carries the HTTP status code field (see [RFC7231],Section 6). This pseudo-header field MUST be included in allresponses; otherwise, the response is malformed (Section 8.1.2.6).

HTTP/2 does not define a way to carry the version or reason phrasethat is included in an HTTP/1.1 status line.

关于asp.net - IISExpress 10 不会通过 HTTPS 返回原因短语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35546143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com