尝试 POST 到 C# ASP.NET Core Web API 中的端点时收到错误 StatusCode 415

问题描述 投票:0回答:1
c# .net-core asp.net-core-webapi
1个回答
0
投票

尝试按以下方式修改您的 HttpPost 方法:

        [HttpPost("ApiTest")]
        [Consumes("application/x-www-form-urlencoded")]
        public IActionResult ApiTest([FromForm] Dictionary<string, string> values)
        {
            string name = values["name"];
            return Ok(new { message = "200: Post Test Succesfull!" });
        }

注意

Consumes
属性,并且
FromBody
变为
FromForm

© www.soinside.com 2019 - 2024. All rights reserved.