From e4c9b95fa3c254e2e565233642d7e244280c53df Mon Sep 17 00:00:00 2001 From: MattMo Date: Wed, 2 Mar 2022 00:44:24 -0800 Subject: [PATCH] Added ReadAsBytes extension and bumped nuget version. --- .../HttpListenerRequestExtensions.cs | 24 +++++++++++++++++++ Rest.Net/Rest.Net/Rest.Net.csproj | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Rest.Net/Rest.Net/Extensions/HttpListenerRequestExtensions.cs b/Rest.Net/Rest.Net/Extensions/HttpListenerRequestExtensions.cs index 6b10bdf..0405a7c 100644 --- a/Rest.Net/Rest.Net/Extensions/HttpListenerRequestExtensions.cs +++ b/Rest.Net/Rest.Net/Extensions/HttpListenerRequestExtensions.cs @@ -52,5 +52,29 @@ namespace MontoyaTech.Rest.Net return default(T); } } + + /// + /// Reads the content of a HttpListenerRequest as a byte array. + /// + /// + /// + public static byte[] ReadAsBytes(this HttpListenerRequest request) + { + try + { + using (var input = request.InputStream) + { + using (var stream = new MemoryStream()) + { + input.CopyTo(stream); + return stream.ToArray(); + } + } + } + catch + { + return null; + } + } } } diff --git a/Rest.Net/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net/Rest.Net.csproj index c5cc1d5..7aed3aa 100644 --- a/Rest.Net/Rest.Net/Rest.Net.csproj +++ b/Rest.Net/Rest.Net/Rest.Net.csproj @@ -14,7 +14,7 @@ MontoyaTech.Rest.Net MontoyaTech.Rest.Net True - 1.0.6 + 1.0.7