【发布时间】:2020-09-25 18:59:30
【问题描述】:
我的一个 WebAPI 的控制器昨天运行良好,但今天我对实际控制器代码之外的项目进行了一些更改,现在 API 无法正确发布。这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Markup;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace SanTool_WebAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class GeneratorStatusController : ControllerBase
{
static List<string> strings = new List<string>()
{
"value0", "value1", "value2"
};
[HttpGet]
public List<string> GetValues()
{
return strings;
}
[HttpPost("{input}")]
public List<string> Post(string input)
{
strings.Add(input);
return strings;
}
}
}
当我使用 IIS 资源管理器运行代码,然后导航到 https://localhost:44312/GeneratorStatus/ 时,它会正确显示我的 [HttpGet](显示三个字符串),但是当我尝试将 post 请求与 https://localhost:44312/GeneratorStatus/2 一起使用,它给了我错误 405 并且不返回字符串
【问题讨论】:
标签: c# post asp.net-web-api http-post