/// <summary> /// Retrieve the raw body as a string from the <see cref="HttpRequest" /> body stream. /// Validates that <paramref name="request" /> and <paramref name="encoding" /> is not null. /// </summary> /// <param name="request">Request instance to apply to.</param> /// <param name="encoding">Optional - Encoding, defaults to UTF8.</param> /// <returns>Task<System.String>.</returns> /// <exception cref="ArgumentNullException">request</exception> /// <remarks>Make sure to call .Dispose on Task,</remarks> public static async Task <string> GetRawBodyStringAsync([NotNull] this HttpRequest request, [NotNull] Encoding encoding) { request = request.ArgumentNotNull(); encoding = encoding.ArgumentNotNull(); using (var reader = new StreamReader(request.Body, encoding)) { return(await reader.ReadToEndAsync().ConfigureAwait(false)); } }