From ed9c36900765e15170f1a5bb6bb8ae013aea51c4 Mon Sep 17 00:00:00 2001 From: wanggaofeng <15601716045@163.com> Date: Fri, 5 Jan 2024 15:45:57 +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 | 11 ++++++++--- HttpClientStudy.WebApp/Program.cs | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/HttpClientStudy.WebApp/Controllers/AdvancedGetController.cs b/HttpClientStudy.WebApp/Controllers/AdvancedGetController.cs index df5bb05..d18a85e 100644 --- a/HttpClientStudy.WebApp/Controllers/AdvancedGetController.cs +++ b/HttpClientStudy.WebApp/Controllers/AdvancedGetController.cs @@ -28,14 +28,19 @@ namespace HttpClientStudy.WebApp.Controllers /// /// [HttpGet] + [HttpPost] public async Task GetWithBodyAsync() { - using (var reader = new StreamReader(Request.Body, Encoding.UTF8, detectEncodingFromByteOrderMarks: false, bufferSize: 1024, leaveOpen: true)) + if (Request.ContentLength>0) { - var body = await reader.ReadToEndAsync(); - // 现在你有了请求体,可以按照你的需求处理它 + 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 536753f..45e4f78 100644 --- a/HttpClientStudy.WebApp/Program.cs +++ b/HttpClientStudy.WebApp/Program.cs @@ -40,8 +40,9 @@ namespace HttpClientStudy.WebApp //Kestrelѡ builder.Services.Configure( option => { - //ͬ IO (getbody) + //(getbody) //ASP.NET Core 3.0 ֮ǰİ汾AllowSynchronousIO Ĭǿ + // true ͬ IO ,Getе.ֱֻӴжȡԶģͰ󶨡 option.AllowSynchronousIO = true; });