Erhalten Sie die Anfrage als Zeichenfolge und Endpointfilter .net 7

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Erhalten Sie die Anfrage als Zeichenfolge und Endpointfilter .net 7

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

Top