【问题标题】:ERR_INVALID_HTTP_RESPONSE using Angular 7 and ASP.Net Core 2.2 in Google Chrome browser在 Google Chrome 浏览器中使用 Angular 7 和 ASP.Net Core 2.2 的 ERR_INVALID_HTTP_RESPONSE
【发布时间】:2019-05-24 19:42:21
【问题描述】:

我有一个应用程序,它使用 Angular 7 作为前端,使用 ASP.Net Core 2.2 提供 API。当我使用 Google Chrome 浏览器发送 POSTPUT 请求时,我收到 ERR_INVALID_HTTP_RESPONSE 错误。

当我将 .Net Core 降级到 2.1 版时,一切正常

此外,当我在 Firefox 中测试我的应用时,一切正常!

我不知道如何解决这个问题

我使用的是 Google Chrome 71 版

当我在谷歌浏览器中查看网络选项卡时,我发现 Chrome 也会向服务器发送预检请求...

这是网络标签中记录的内容:

第一:

Request URL: http://localhost:12346/api/XXXX
Request Method: OPTIONS
Status Code: 204 No Content
Remote Address: [::1]:12346
Referrer Policy: no-referrer-when-downgrade

那么:(导致错误的原因)

Request URL: http://localhost:12346/api/XXXX
Referrer Policy: no-referrer-when-downgrade

如您所见,chrome 不会向服务器发送任何 POST 请求(应该发送)。

【问题讨论】:

  • @Vahid 找到解决方案了吗?
  • @AnthonyLiriano 还没有。这个问题让我暂时降级到 .Net Core 2.1。

标签: angular google-chrome asp.net-core angular7


【解决方案1】:

如您所想,这可能与 ASP NET Core 2.2 有关。在 GitHub 上注册了一个问题 https://github.com/aspnet/AspNetCore/issues/4398

解决方法如下 - 在您的 startup.cs 类中添加以下代码(我在 Configure 方法中首先保留了此代码)

app.Use(async (ctx, next) =>
{
  await next();
  if (ctx.Response.StatusCode == 204)
  {
    ctx.Response.ContentLength = 0;
  }
});

请跟踪 GitHub 问题。

【讨论】:

  • 截至上个晚上,修复已合并到 ASP.NET Core 2.2.1 的 SDK 中。如果您下载并安装它,则不再需要解决方法。
猜你喜欢
  • 2019-07-15
  • 2019-08-22
  • 1970-01-01
  • 1970-01-01
  • 2015-02-27
  • 1970-01-01
  • 2019-08-22
  • 1970-01-01
  • 2019-12-27
相关资源
最近更新 更多