示例代码:
// 客户端代码 fetch('https://example.com/api/mycontroller', { method: 'POST', body: JSON.stringify(data), headers: { 'Content-Type': 'application/json' } }) .then(response => { console.log(response); }) .catch(error => { console.error(error); });
// Web API 控制器代码 [ApiController] [Route("api/[controller]")] public class MyController : ControllerBase { [HttpPost] public IActionResult Post([FromBody] MyModel model) { // 处理请求 return Ok(); } }