by Anonymous » 01 Mar 2025, 13:56
Ich habe einen einfachen Endpunktfilter auf einer C# minimalen API erstellt und wenn ich versuche, den Körper in eine Zeichenfolge zu bringen, ist er immer leer. < /p>
Code: Select all
app.MapPost("/todo", async (Todo todo) =>
{
await Task.Run(() => { string x = "R";});
return Results.Created($"/todo/{0}", 1);
})
.WithName("PostToDo")
.WithOpenApi()
.AddEndpointFilter(async (context, next) =>
{
var body = context.HttpContext.Request.Body;
using (var bodyReader = new StreamReader(body))
{
string rawBody = await bodyReader.ReadToEndAsync();
}
var result = await next(context);
return result;
});
Ich habe einen einfachen Endpunktfilter auf einer C# minimalen API erstellt und wenn ich versuche, den Körper in eine Zeichenfolge zu bringen, ist er immer leer. < /p>
[code]app.MapPost("/todo", async (Todo todo) =>
{
await Task.Run(() => { string x = "R";});
return Results.Created($"/todo/{0}", 1);
})
.WithName("PostToDo")
.WithOpenApi()
.AddEndpointFilter(async (context, next) =>
{
var body = context.HttpContext.Request.Body;
using (var bodyReader = new StreamReader(body))
{
string rawBody = await bodyReader.ReadToEndAsync();
}
var result = await next(context);
return result;
});
[/code]