main
wanggaofeng 1 year ago
parent 2f98ab7c76
commit e57bd3c22c

@ -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);
}
}
}

@ -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 =>
{

Loading…
Cancel
Save