lcl 6 bulan lalu
induk
melakukan
68af0072c9
1 mengubah file dengan 10 tambahan dan 10 penghapusan
  1. 10 10
      Extensions/HttpContextExtension.cs

+ 10 - 10
Extensions/HttpContextExtension.cs

@@ -173,11 +173,11 @@ namespace Extensions
         /// <returns></returns>
         public static string GetBody(this HttpContext context)
         {
-            // context.Request.EnableBuffering();
-            //context.Request.Body.Seek(0, SeekOrigin.Begin);
-            //using var reader = new StreamReader(context.Request.Body, Encoding.UTF8);
-            ////需要使用异步方式才能获取
-            //return reader.ReadToEndAsync().Result;
+            context.Request.EnableBuffering();
+            context.Request.Body.Seek(0, SeekOrigin.Begin);
+            using var reader = new StreamReader(context.Request.Body, Encoding.UTF8);
+            //需要使用异步方式才能获取
+            return reader.ReadToEndAsync().Result;
             // string body = string.Empty;
             // var buffer = new MemoryStream();
             // context.Request.Body.Seek(0, SeekOrigin.Begin);
@@ -193,11 +193,11 @@ namespace Extensions
             //     buffer?.Dispose();
             // }
             // return body;
-            var reader = new StreamReader(context.Request.Body, Encoding.UTF8);
-            //需要使用异步方式才能获取
-            string content = reader.ReadToEnd();
-            reader.Dispose();
-            return content;
+            // var reader = new StreamReader(context.Request.Body, Encoding.UTF8);
+            // //需要使用异步方式才能获取
+            // string content = reader.ReadToEnd();
+            // reader.Dispose();
+            // return content;
         }
 
         /// <summary>