You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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]
[HttpPost]
public async Task < IActionResult > GetWithBodyAsync ( )
{
if ( Request . ContentLength > 0 )
{
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 ) ;
}
}
}