private string ReadFrom(Stream bodyStream) { try { using (var bodyReader = new HttpRequestStreamReader(bodyStream, Encoding.UTF8)) { return(bodyReader.ReadToEnd()); } } catch (Exception ex) when(ex is IOException || ex is OutOfMemoryException || ex is ArgumentOutOfRangeException || ex is ObjectDisposedException) { return(string.Empty); } }
public ActionResult <ResolvedURL> Submit() { using (var streamReader = new HttpRequestStreamReader(Request.Body, System.Text.Encoding.UTF8)) { // deserialize JSON URLContainer urlObj = JsonConvert.DeserializeObject <URLContainer>(streamReader.ReadToEnd()); ResolvedURL randomUrl = LinkGenerator.AddURL(urlObj.url); return(randomUrl); } }