ein
Code: Select all
builder.Services.AddHttpLogging(logging =>
{
logging.LoggingFields = HttpLoggingFields.All;
});
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpLogging();
< /code>
und Änderung der Protokollierungsstufe in AppStings.development.json < /p>
"Microsoft.AspNetCore": "Information"
Request:
Protocol: HTTP/1.1
Method: POST
Scheme: https
PathBase:
Path: /WeatherForecast
Accept: */*
Connection: keep-alive
Host: localhost:7269
User-Agent: PostmanRuntime/7.29.0
Accept-Encoding: gzip, deflate, br
Content-Type: application/json
Content-Length: 60
Postman-Token: [Redacted]
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'WebApplication1.Controllers.WeatherForecastController.Post (WebApplication1)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
Route matched with {action = "Post", controller = "WeatherForecast"}. Executing controller action with signature System.Collections.Generic.IEnumerable`1[WebApplication1.WeatherForecast] Post() on controller WebApplication1.Controllers.WeatherForecastController (WebApplication1).
info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
Executing ObjectResult, writing value of type 'WebApplication1.WeatherForecast[]'.
info: Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware[2]
Response:
StatusCode: 200
Content-Type: application/json; charset=utf-8
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
Executed action WebApplication1.Controllers.WeatherForecastController.Post (WebApplication1) in 8.0904ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'WebApplication1.Controllers.WeatherForecastController.Post (WebApplication1)'
info: Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware[3]
RequestBody: //
Ich weiß jedochusing var reader = new StreamReader(HttpContext.Request.Body);
var myBody = await reader.ReadToEndAsync(); // {"username": "josef","password": "MyPassword"}
< /code>
Es gibt ein vom Postman generierter Anforderungs -Curl -Beispiel. < /p>
curl --location --request POST 'https://localhost:7269/WeatherForecast' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "josef",
"password": "MyPassword"
}'
< /code>
Ich weiß nicht, ob es einen Schritt gibt, den ich verpasst habe oder so etwas. Ich habe versucht, verschiedene Protokollebenen, unterschiedliche Anforderungstypen, Körper und Körpertypen zu ändern. Der RequestBody ist im Protokoll immer leer. Ich verstehe nicht, warum es sich nur melden sollte, wenn ich den Körper manuell lese.
Mobile version