Exemplo n.º 1
0
 public override Boolean CanRead(InputFormatterContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     return(SupportedMediaTypes.Any(m => context.IsFromContentType(m)));
 }
Exemplo n.º 2
0
        public override async Task <InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context)
        {
            var request = context.HttpContext.Request;

            if (context.IsFromContentType("text/json"))
            {
                using (var reader = new StreamReader(request.Body))
                {
                    var content = await MIMETypeToString(reader);

                    return(await InputFormatterResult.SuccessAsync(content));
                }
            }
            return(await InputFormatterResult.FailureAsync());
        }