From e57bd3c22cb1fed2ea0a6da61a52ed1b39c58ea6 Mon Sep 17 00:00:00 2001
From: wanggaofeng <15601716045@163.com>
Date: Fri, 5 Jan 2024 14:43:48 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Controllers/AdvancedGetController.cs      | 43 +++++++++++++++++++
 HttpClientStudy.WebApp/Program.cs             |  9 ++++
 2 files changed, 52 insertions(+)
 create mode 100644 HttpClientStudy.WebApp/Controllers/AdvancedGetController.cs

diff --git a/HttpClientStudy.WebApp/Controllers/AdvancedGetController.cs b/HttpClientStudy.WebApp/Controllers/AdvancedGetController.cs
new file mode 100644
index 0000000..df5bb05
--- /dev/null
+++ b/HttpClientStudy.WebApp/Controllers/AdvancedGetController.cs
@@ -0,0 +1,43 @@
+using System.Text;
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace HttpClientStudy.WebApp.Controllers
+{
+    /// <summary>
+    /// 高级Get请求 控制器
+    /// </summary>
+    [Route("api/[controller]/[action]")]
+    [ApiController]
+    public class AdvancedGetController : ControllerBase
+    {
+        private ILogger<SimpleController> _logger;
+
+        /// <summary>
+        /// 构造
+        /// </summary>
+        public AdvancedGetController(ILogger<SimpleController> logger)
+        { 
+            _logger = logger;
+        }
+
+        /// <summary>
+        /// 带请求体数据的Get请求
+        /// (asp.net 3开始,默认不允许Get有Body)
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        public async Task<IActionResult> GetWithBodyAsync()
+        {
+            using (var reader = new StreamReader(Request.Body, Encoding.UTF8, detectEncodingFromByteOrderMarks: false, bufferSize: 1024, leaveOpen: true))
+            {
+                var body = await reader.ReadToEndAsync();
+                // 现在你有了请求体,可以按照你的需求处理它
+            }
+
+            var reslut = BaseResultUtil.Success("操作成功");
+            return Ok(reslut);
+        }
+    }
+}
diff --git a/HttpClientStudy.WebApp/Program.cs b/HttpClientStudy.WebApp/Program.cs
index 4ca0d05..536753f 100644
--- a/HttpClientStudy.WebApp/Program.cs
+++ b/HttpClientStudy.WebApp/Program.cs
@@ -3,6 +3,7 @@ using System.Text;
 
 using Microsoft.AspNetCore.Authentication.Cookies;
 using Microsoft.AspNetCore.Http.Features;
+using Microsoft.AspNetCore.Server.Kestrel.Core;
 using Microsoft.IdentityModel.Tokens;
 using Microsoft.OpenApi.Models;
 
@@ -36,6 +37,14 @@ namespace HttpClientStudy.WebApp
                 option.IdleTimeout = TimeSpan.FromHours(1);
             });
 
+            //����Kestrel������ѡ��
+            builder.Services.Configure<KestrelServerOptions>( option => 
+            {
+                //����ͬ�� IO ����(����get����������body)
+                //ASP.NET Core 3.0 ֮ǰ�İ汾��AllowSynchronousIO Ĭ���ǿ�����
+                option.AllowSynchronousIO = true;
+            });
+
             //����Form�����ύѡ��
             builder.Services.Configure<FormOptions>(options => 
             {