为什么我启用路由的 HttpGet 方法被视为不支持 GET?

Why is my route-enabled HttpGet method viewed as not supporting GET?

我有一对 GET 和 POST Web API 方法可以正常工作。我有另一对似乎以完全相同的方式设置,但 GET 方法拒绝接受调用。所有这样做的尝试都以消息“请求的资源不支持 http 方法 'GET'”结束。“

然而(再次)此 GET 方法的设置和修饰与工作方法相同。

这是有效的(未标记的"GET"(第一种方法)和标记的"POST"在调用时均已成功输入):

[RoutePrefix("api/pricecompliance")]
public class PriceComplianceController : ApiController
{

    [Route("{unit}/{begindate}")]
    public HttpResponseMessage Get(string unit, string begindate)
    {
        . . .


    [Route("{unit}/{begindate}")]
    [HttpPost]
    public void Post(string unit, string begindate)
    {
        . . .

...这是看起来几乎相同的一对(当然名称不同,还有一个参数):

[RoutePrefix("api/produceusage")]
public class ProduceUsageController : ApiController
{
    [Route("{unit}/{begindate}/{enddate}")]
    public HttpResponseMessage Get(string unit, string beginRange, string 
endRange)
    {
        . . .

    [Route("{unit}/{begindate}/{enddate}")]
    [HttpPost]
    public void Post(string unit, string begindate, string enddate)
    {
        . . .

如前所述,使用无效的第二块代码,当我尝试调用 "GET" 时,我得到:

请求的资源不支持http方法'GET'。

我确实像这样设置了属性路由:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services
        // Configure Web API to use only bearer token authentication.
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

        // Web API routes
        config.MapHttpAttributeRoutes();

为什么在后一种情况下不支持 GET?

当我尝试通过单击带有 URL 的 link 来调用 GET 时,以及当我尝试使用“[= 从 Postman 调用它时13=]",我得到了同样的 "GET not supported" 爵士乐。

原来我不得不改这个:

public HttpResponseMessage Get(string unit, string beginRange, string endRange)

...为此:

public HttpResponseMessage Get(string unit, string begindate, string enddate)

...以便参数名称与路由中的名称完全匹配:

[Route("{unit}/{begindate}/{enddate}")]

为什么这很重要我不知道,但确实如此。