You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用POST API时Postman返回404 Not Found,求排查方案

解决POST API返回404 Not Found的问题

以下是核心排查方向和解决方案:

1. 路由不匹配(最可能原因)

你的请求URL是https://localhost:44458/api/Customer_CRUD,但ASP.NET Core默认路由规则是:

  • 若控制器类名为CustomerController,且带有[Route("api/[controller]")]属性,路由前缀应为api/Customer
  • 当前请求的Customer_CRUD与控制器默认路由不匹配,导致接口无法被找到

修正方式:

  • 修改请求URL:将Postman请求URL改为https://localhost:44458/api/Customer(对应控制器默认路由)
  • 修改控制器路由:若需保留Customer_CRUD作为路由前缀,在控制器类上显式设置:
    [ApiController]
    [Route("api/Customer_CRUD")]
    public class CustomerController : ControllerBase
    {
        // 你的PostCustomer方法代码
    }
    

2. 端口号验证

确认项目启动的HTTPS端口是否为44458,可查看项目根目录下的launchSettings.json文件,检查applicationUrl中的HTTPS端口是否一致。

3. 请求头配置检查

在Postman中确保请求的Content-Type设置为application/json,虽不会直接导致404,但可排除后续模型绑定的潜在问题。

4. 控制器类完整性检查

确认控制器类继承自ControllerBase,且添加了[ApiController]属性,这是ASP.NET Core Web API的必要配置。

内容的提问来源于stack exchange,提问作者Harinder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 15:27:12