HttpServer.HttpRequest.DecodeBody C# (CSharp) Method

DecodeBody() public method

Decode body into a form.
If body contents is not valid for the chosen decoder. If body is still being transferred.
public DecodeBody ( FormDecoderProvider providers ) : void
providers FormDecoderProvider A list with form decoders.
return void
        public void DecodeBody(FormDecoderProvider providers)
        {
            if (_bodyBytesLeft > 0)
                throw new InvalidOperationException("Body have not yet been completed.");

            _form = providers.Decode(_headers["content-type"], _body, Encoding.UTF8);
            if (_form != HttpInput.Empty)
                _param.SetForm(_form);
        }

Usage Example

 /// <summary>
 /// Decodes the request body.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <exception cref="InternalServerException">Failed to decode form data.</exception>
 protected virtual void DecodeBody(HttpRequest request)
 {
     try
     {
         if (request.Body.Length > 0)
             request.DecodeBody(_formDecodersProvider);
     }
     catch (InvalidOperationException err)
     {
         throw new InternalServerException("Failed to decode form data.", err);
     }
     catch (InvalidDataException err)
     {
         throw new InternalServerException("Form contains invalid format.", err);
     }
 }