【发布时间】:2020-05-18 05:17:40
【问题描述】:
考虑控制器:
public class EmployeeController : ApiController
{
// https://localhost:44344/api/employee/:profession
[HttpGet]
[Route("api/employee/{profession}")]
public HttpResponseMessage Get(String profession)
{
try
{
var someBigList = ...
/// ... do some stuff
return Request.CreateResponse(HttpStatusCode.OK, someBigList );
}
catch (Exception e)
{
// error
}
}
}
控制器接受以下形式的请求:
https://localhost:44344/api/employee/:profession
但是当我尝试时
https://localhost:44344/api/employee
它没有。
我们如何修复 GET 请求以接受两者?
【问题讨论】:
-
公共 HttpResponseMessage 获取(字符串职业 = null)
-
@SirRufo:不起作用
-
提醒自己:不要在一天的第一杯咖啡之前评论/回答;o)
标签: c# .net asp.net-web-api webapi