This commit is contained in:
zpc 2026-02-04 01:05:08 +08:00
parent 18e6f339d6
commit ae169a6785
2 changed files with 51 additions and 4 deletions

View File

@ -80,12 +80,13 @@ public class WelfareController : ControllerBase
/// </summary>
[HttpGet("fuliwu")]
[HttpPost("fuliwu")]
public async Task<ApiResponse<FuliwuListResponse>> GetFuliwuList([FromForm] FuliwuListRequest? request)
public async Task<ApiResponse<FuliwuListResponse>> 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;

View File

@ -173,6 +173,13 @@ try
// 使用 Serilog 请求日志
app.UseSerilogRequestLogging();
// 启用请求体缓冲,允许多次读取
app.Use(async (context, next) =>
{
context.Request.EnableBuffering();
await next();
});
// 使用路由
app.UseRouting();