© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
26 replies
Matheus

Body request

hey there, I'm trying to get the body with this method
public async Task<string?> ReadRequestBodyAsync(HttpRequest request)
{
    request.EnableBuffering();

    if (request.Body == null)
    {
        throw new ArgumentNullException(nameof(request.Body), "Request body is null.");
    }

    using (var reader = new StreamReader(request.Body, Encoding.UTF8, leaveOpen: true))
    {
        var body = await reader.ReadToEndAsync();
        return body;
    }
    

}
public async Task<string?> ReadRequestBodyAsync(HttpRequest request)
{
    request.EnableBuffering();

    if (request.Body == null)
    {
        throw new ArgumentNullException(nameof(request.Body), "Request body is null.");
    }

    using (var reader = new StreamReader(request.Body, Encoding.UTF8, leaveOpen: true))
    {
        var body = await reader.ReadToEndAsync();
        return body;
    }
    

}

but when i will go to see the parameters, don't contain the body and I'm using HttpRequest to do this, exist another way to do this?
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ c# post request http body
C#CC# / help
3y ago
❔ HttpContext reading Request and Response body
C#CC# / help
3y ago
❔ how to get city data from request body?
C#CC# / help
3y ago