src/packages/EmbedIO/HttpContextExtensions-Requests.cs
/// <summary>
/// Asynchronously parses a request body in <c>application/x-www-form-urlencoded</c> format.
/// </summary>
/// <param name="this">The <see cref="IHttpContext"/> on which this method is called.</param>
/// <returns>A <see cref="Task{TResult}">Task</see>, representing the ongoing operation,
/// whose result will be a read-only <see cref="NameValueCollection"/>of form field names and values.</returns>
/// <exception cref="NullReferenceException"><paramref name="this"/> is <see langword="null"/>.</exception>
/// <remarks>
/// <para>This method may safely be called more than once for the same <see cref="IHttpContext"/>:
/// it will return the same collection instead of trying to parse the request body again.</para>
/// </remarks>
Asynchronously parses a request body in application/x-www-form-urlencoded
Asynchronously parses a request body in application / x - www - form - urlencoded
public static async Task<NameValueCollection> GetRequestFormDataAsync(this IHttpContext @this)
        {
            if (!@this.Items.TryGetValue(FormDataKey, out var previousResult))
            {
                NameValueCollection result;
                try
                {
                    using var reader = @this.OpenRequestText();
                    result = UrlEncodedDataParser.Parse(await reader.ReadToEndAsync().ConfigureAwait(false), false);
                }
                catch (Exception e)
                {
                    @this.Items[FormDataKey] = e;
                    throw;
                }
                @this.Items[FormDataKey] = result;
                return result;
            }
            return previousResult switch
            {
                NameValueCollection collection => collection,
                Exception exception => throw exception.RethrowPreservingStackTrace(),
                null => throw SelfCheck.Failure($"Previous result of {nameof(HttpContextExtensions)}.{nameof(GetRequestFormDataAsync)} is null."),
                _ => throw SelfCheck.Failure($"Previous result of {nameof(HttpContextExtensions)}.{nameof(GetRequestFormDataAsync)} is of unexpected type {previousResult.GetType().FullName}"),
            };
        }
public static async Task < NameValueCollection > GetRequestFormDataAsync ( this IHttpContext @this ) { if ( ! @this . Items . TryGetValue ( FormDataKey , out var previousResult ) ) { NameValueCollection result ; try { using var reader = @this . OpenRequestText ( ) ; result = UrlEncodedDataParser . Parse ( await reader . ReadToEndAsync ( ) . ConfigureAwait ( false ) , false ) ; } catch ( Exception e ) { @this . Items [ FormDataKey ] = e ; throw ; } @this . Items [ FormDataKey ] = result ; return result ; } return previousResult switch { NameValueCollection collection => collection , Exception exception => throw exception . RethrowPreservingStackTrace ( ) , null => throw SelfCheck . Failure ( $" Previous result of  { nameof ( HttpContextExtensions ) } . { nameof ( GetRequestFormDataAsync ) }  is null. " ) , _ => throw SelfCheck . Failure ( $" Previous result of  { nameof ( HttpContextExtensions ) } . { nameof ( GetRequestFormDataAsync ) }  is of unexpected type  { previousResult . GetType ( ) . FullName } " ) , } ; }
Asynchronously parses a request body in application/x-www-form-urlencoded
Asynchronously parses a request body in application / x - www - form - urlencoded
A Taskof form field names and values.
A Taskof form field names and values .
None
IHttpContext
this
this
The  on which this method is called.
The on which this method is called .
remarks
This method may safely be called more than once for the same :
it will return the same collection instead of trying to parse the request body again.
This method may safely be called more than once for the same : it will return the same collection instead of trying to parse the request body again .