public static string ReadBodyStream(this HttpRequest httpRequest) { httpRequest.EnableRewind(); var reader = new StreamReader(httpRequest.Body); var body = reader.ReadToEnd(); if (httpRequest.Body.CanSeek) { httpRequest.Body.Seek(0, SeekOrigin.Begin); } return(body); }
private static void WriteBody(HttpRequest request, StringWriter writer) { // HACK: change the body stream so that it can be read and then repositoned to the beginning // see https://github.com/aspnet/KestrelHttpServer/issues/1113 request.EnableRewind(); StreamReader reader = new StreamReader(request.Body); try { string body = reader.ReadToEnd(); if (body.Length > 0) { writer.WriteLine(); writer.Write(body); } } finally { request.Body.Position = 0; } }