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