The application completed without reading the entire request body, .net core 2.1.1
It happened to me in a new ASP.NET Core 2.1 service when debugging in localhost because I had in Startup.Configure:
app.UseHttpsRedirection();
I deactivated this setting when debugging locally:
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHttpsRedirection();
}
The error info of the application completed without reading the entire request body
often occurs when the client send a request that doesn't fulfill the sever requirements . In other words , it happens just before entering the action , resulting that you cannot debug it via a breakpoint within the body of action method .
For example , let's say a action method on the server :
[Route("api/[controller]")]
[ApiController]
public class DummyController : ControllerBase
{
[HttpPost]
public DummyDto PostTest([FromBody] DummyDto dto)
{
return dto;
}
}
The DummyDto
here is a dummy class to hold information:
public class DummyDto
{
public int Id { get; set; }
}
When clients send a request with payload not well formatted
For example , the following post request , which doesn't have a Content-Type: application/json
header :
POST https://localhost:44306/api/test HTTP/1.1
Accept : application/json
{ "id":5 }
will result in a similar error info :
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 POST http://localhost:44306/api/test 10
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 1.9319ms 404
Microsoft.AspNetCore.Server.Kestrel:Information: Connection id "0HLGH8R93RPUO", Request id "0HLGH8R93RPUO:00000002": the application completed without reading the entire request body.
and the response from the server will be 404
:
HTTP/1.1 404 Not Found
Server: Kestrel
X-SourceFiles: =?UTF-8?B?RDpccmVwb3J0XDIwMThcOVw5LTFcU08uQXV0aFJlYWRpbmdXaXRob3V0RW50aXRlQm9keVxBcHBcQXBwXGFwaVx0ZXN0?=
X-Powered-By: ASP.NET
Date: Mon, 03 Sep 2018 02:42:53 GMT
Content-Length: 0
As for the question you described , I suggest you should check the following list :
- does the Postman send the request with a header of
Content-Type: application/json
? make sure you have checked the header - If step1 doesn't work , click the
code
to show what it sends exactly when you send a request to the server .
There can be multiple reasons out of which one can be : – Caching in Visual Studio --
1.Close all the instances of visual studios, run Developer command prompt with Admin rights.
2.git clean -xfd [Your Repository to remove all dependencies and existing soln file]
3.take the latest build and run . [Make Endpoint AllowAnonymous]