Erhalten Sie die Anfrage als Zeichenfolge und Endpointfilter .net 7C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Erhalten Sie die Anfrage als Zeichenfolge und Endpointfilter .net 7

Post by Anonymous »

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;
});

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post