.net core 404试图在Ocelot中将上游路径路由到下游路径

.net core 404试图在Ocelot中将上游路径路由到下游路径,.net-core,microservices,api-gateway,ocelot,.net Core,Microservices,Api Gateway,Ocelot,将传入的http请求转发到下游路径时,我面临此警告/错误 Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware: 警告:请求ID:80000025-0004-fd00-b63f-84710c7967bb, previousRequestId:没有以前的请求id,消息: DownstreamRouteFinderMiddleware设置管道错误。 IDownstreamRouteFinder返回错误代码: U

将传入的http请求转发到下游路径时,我面临此警告/错误

Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware: 警告:请求ID:80000025-0004-fd00-b63f-84710c7967bb, previousRequestId:没有以前的请求id,消息: DownstreamRouteFinderMiddleware设置管道错误。 IDownstreamRouteFinder返回错误代码: UnabletoFindDownstreamRoute错误消息:无法匹配路由 上游路径的配置:/getDepartment,动词:GET

Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
       WebHost.CreateDefaultBuilder(args)
       .ConfigureAppConfiguration((host, config) =>
       {
           config.AddJsonFile("ocelot.json");
       })
    .UseStartup<Startup>();
}
ocelot.json

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "api/department",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 44388
        }
      ],
      "UpstreamPathTemplate": "/getDepartment",
      "UpstreamHttpMethod": [
        "Get"
      ]
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:5000"
  }
}

我在这里得到了错误404

如果您使用的是最新版本(16.0.0),请将ocelot.json中的“ReRoutes”更改为“Routes”

我也遇到了同样的问题,然后遇到了这个拉请求,解释说它已经被更改为与新的Microsoft反向代理项目(YARP)相匹配。他们的文件需要更新。

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "api/department",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 44388
        }
      ],
      "UpstreamPathTemplate": "/getDepartment",
      "UpstreamHttpMethod": [
        "Get"
      ]
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:5000"
  }
}