diff options
author | crupest <crupest@outlook.com> | 2019-02-14 23:05:04 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-02-14 23:05:04 +0800 |
commit | 3c140656ebe6ed34dda9356a01dbff205651e641 (patch) | |
tree | 8b8ca7331c9510b897042737a5cbbc0f77b1b736 /Timeline/Formatters/StringInputFormatter.cs | |
parent | de90f0413553a23f8ebba1343c6e96c63e0c9748 (diff) | |
download | timeline-3c140656ebe6ed34dda9356a01dbff205651e641.tar.gz timeline-3c140656ebe6ed34dda9356a01dbff205651e641.tar.bz2 timeline-3c140656ebe6ed34dda9356a01dbff205651e641.zip |
Develop user token interface.
Diffstat (limited to 'Timeline/Formatters/StringInputFormatter.cs')
-rw-r--r-- | Timeline/Formatters/StringInputFormatter.cs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Timeline/Formatters/StringInputFormatter.cs b/Timeline/Formatters/StringInputFormatter.cs new file mode 100644 index 00000000..f2475137 --- /dev/null +++ b/Timeline/Formatters/StringInputFormatter.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.Net.Http.Headers; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Timeline.Formatters +{ + public class StringInputFormatter : TextInputFormatter + { + public StringInputFormatter() + { + SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("text/plain")); + + SupportedEncodings.Add(Encoding.UTF8); + SupportedEncodings.Add(Encoding.Unicode); + } + + public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding effectiveEncoding) + { + var request = context.HttpContext.Request; + using (var reader = new StreamReader(request.Body, effectiveEncoding)) + { + var stringContent = reader.ReadToEnd(); + return InputFormatterResult.SuccessAsync(stringContent); + } + } + } +} |