net::ERR_INVALID_HTTP_RESPONSE error after post request with Angular 7

后端 未结 3 1984
耶瑟儿~
耶瑟儿~ 2021-02-13 11:25

I am working on small web application and I am using angular 7 and asp.net core web api as a back end. I am trying to make http post request with angular. My service returns str

3条回答
  •  遇见更好的自我
    2021-02-13 12:02

    In ASP.NET Core 2.2, we released a new Server which runs inside IIS for Windows scenarios. The issue you are running into looks like: https://github.com/aspnet/AspNetCore/issues/4398.

    When sending the XMLHttpRequest, there is a preflight OPTIONS request which returns a status code of 204. This was incorrectly handled by the IIS server, returning an invalid response to the client.

    In your ASP.NET Core application, can you please try the workaround for now:

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

    in the beginning of Configure method.

    This will also be fixed in the next patch release of ASP.NET Core. I will follow up when the patch is released.

    Edit: The latest release (2.2.1) should address this problem: https://dotnet.microsoft.com/download/dotnet-core/2.2. Please try and see if the issue is resolved.

提交回复
热议问题