Dot-Net-Core
404 嘗試將上游路徑路由到 Ocelot 中的下游路徑
在將傳入的 http 請求轉發到下游路徑時,我遇到了這個警告/錯誤。
Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware:警告:requestId:80000025-0004-fd00-b63f-84710c7967bb,previousRequestId:沒有先前的請求 id,消息:DownstreamRouteFinderMiddleware 設置管道錯誤。IDownstreamRouteFinder 返回錯誤程式碼:UnableToFindDownstreamRouteError 消息:無法匹配上游路徑的路由配置:/getDepartment,動詞:GET。
程序.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>(); }啟動.cs
public IConfiguration Configuration { get; } public Startup(IConfiguration configuration) { Configuration = configuration; } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddOcelot(Configuration); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } await app.UseOcelot(); app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); }豹貓.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) 相匹配。他們的文件需要更新。 https://github.com/ThreeMammals/Ocelot/pull/1239