diff --git a/server/HoneyBox/src/HoneyBox.Api/Controllers/WelfareController.cs b/server/HoneyBox/src/HoneyBox.Api/Controllers/WelfareController.cs index 1a9a18a2..b9395e1a 100644 --- a/server/HoneyBox/src/HoneyBox.Api/Controllers/WelfareController.cs +++ b/server/HoneyBox/src/HoneyBox.Api/Controllers/WelfareController.cs @@ -80,12 +80,13 @@ public class WelfareController : ControllerBase /// [HttpGet("fuliwu")] [HttpPost("fuliwu")] - public async Task> GetFuliwuList([FromForm] FuliwuListRequest? request) + public async Task> GetFuliwuList() { - // 尝试从Query获取参数 (GET请求) - var type = request?.Type ?? 1; - var page = request?.Page ?? 1; + // 从多种来源获取参数 + var type = 1; + var page = 1; + // 1. 尝试从 Query 获取 (GET请求) if (Request.Query.ContainsKey("type")) { int.TryParse(Request.Query["type"], out type); @@ -95,6 +96,45 @@ public class WelfareController : ControllerBase int.TryParse(Request.Query["page"], out page); } + // 2. 尝试从 Form 获取 (POST form-urlencoded) + if (Request.HasFormContentType) + { + if (Request.Form.ContainsKey("type")) + { + int.TryParse(Request.Form["type"], out type); + } + if (Request.Form.ContainsKey("page")) + { + int.TryParse(Request.Form["page"], out page); + } + } + // 3. 尝试从 JSON Body 获取 (POST application/json) + else if (Request.ContentType?.Contains("application/json") == true) + { + try + { + Request.Body.Position = 0; + using var reader = new StreamReader(Request.Body); + var body = await reader.ReadToEndAsync(); + if (!string.IsNullOrEmpty(body)) + { + var json = System.Text.Json.JsonDocument.Parse(body); + if (json.RootElement.TryGetProperty("type", out var typeElement)) + { + type = typeElement.GetInt32(); + } + if (json.RootElement.TryGetProperty("page", out var pageElement)) + { + page = pageElement.GetInt32(); + } + } + } + catch (Exception ex) + { + _logger.LogWarning("Failed to parse JSON body: {Error}", ex.Message); + } + } + // 获取用户ID (可选,未登录用户也可以查看) var userId = GetCurrentUserId() ?? 0; diff --git a/server/HoneyBox/src/HoneyBox.Api/Program.cs b/server/HoneyBox/src/HoneyBox.Api/Program.cs index d5d6982f..65235475 100644 --- a/server/HoneyBox/src/HoneyBox.Api/Program.cs +++ b/server/HoneyBox/src/HoneyBox.Api/Program.cs @@ -173,6 +173,13 @@ try // 使用 Serilog 请求日志 app.UseSerilogRequestLogging(); + // 启用请求体缓冲,允许多次读取 + app.Use(async (context, next) => + { + context.Request.EnableBuffering(); + await next(); + }); + // 使用路由 app.UseRouting();