I have an application which is using Angular 7 for the front end and ASP.Net Core 2.2 for serving APIs. When I am sending POST
or PUT
requests using Google Chrome browser, I get ERR_INVALID_HTTP_RESPONSE
error.
When I downgrade my .Net Core to version 2.1, everything works fine
Also when I am testing my app in Firefox, again everything is working fine!
I do not know how to resolve this issue
I am using Google Chrome version 71
When I check the Network tab in Google Chrome, I found that Chrome sends a preflight request to the server too...
Here is what recorded in Network tab:
First:
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
Then:(which cause the error)
Request URL: http://localhost:12346/api/XXXX
Referrer Policy: no-referrer-when-downgrade
As you see chrome does not send any POST
request to the server (which should send).
This may have to do with ASP NET Core 2.2 as you figured. There's an issue registered on GitHub https://github.com/aspnet/AspNetCore/issues/4398
And the work-around is as follows - add the following bit of code in your startup.cs
class (I've kept this first in Configure
method)
app.Use(async (ctx, next) =>
{
await next();
if (ctx.Response.StatusCode == 204)
{
ctx.Response.ContentLength = 0;
}
});
Do keep track of the GitHub issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With