【问题标题】:WebApi 2.0 Endpoint not being hit with decimal and intWebApi 2.0 端点没有被小数和整数命中
【发布时间】:2018-04-12 07:49:35
【问题描述】:

我有以下 Asp.Net Core 2.0 Web API 控制器:

[Route("api/[controller]")]
public class TraderController : Controller
{
}

以及以下端点:

[HttpGet]
[ProducesResponseType(typeof(IList<Trader>), 200)]
[Route("/find/{category:int}/{latitude:decimal}/{longitude:decimal}/")]
public IActionResult FindTraders(int category, decimal latitude, decimal longitude)
{ 

}

但是,当我使用 HTTP GET 时,我收到了 404 错误:

http://localhost:59405/api/trader/find/3/41.14271100000001/-8.611171499999955/

谁能告诉我我在这里做错了什么?还有其他端点正在命中,但不是这个。可能与路线中的小数有关吗?

【问题讨论】:

    标签: c# asp.net-core-2.0 asp.net-core-webapi


    【解决方案1】:

    要么你必须使用 HTTP GET 像

    http://localhost:59405/api/trader/find?category=3&latitude=41.14271100000001&longitude=-8.611171499999955

    或尝试将端点 url 更改为

    [Route("/find/{category=category:int}/{latitude=latitude:decimal}/{longitude=longitude:decimal}/")]
    

    【讨论】:

    • 我已经厌倦了上面列出的两种组合,但都不起作用?我添加了尾随 / 以避免 IIS 认为端点是一个文件(但我尝试过使用和不使用它仍然导致 4040 错误)还有其他想法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    相关资源
    最近更新 更多