OCELOT API网关实施中的帖子动词的问题

发布于 01-23 13:13 字数 1176 浏览 5 评论 0 原文

这是我的ocelot.json,当我击中 https:// localhost:44368/weatherforecast 时,它可以正常工作。但是,当我发布post https:// localhost:44368/login 的用户登录请求时,它会返回404错误。我真的很想念我找不到。但是当我使用直接URL时,它可以正常工作。 swagger_result

Console Log
Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /Login, verb: POST
ocelot.json file
{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api​/WeatherForecast​/Get",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "44385"
        }
      ],
      "UpstreamPathTemplate": "/WeatherForecast",
      "UpstreamHttpMethod": [
        "GET"
      ]
    },
    {
      "DownstreamPathTemplate": "/api​/Auth​/Login",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "44320"
        }
      ],
      "UpstreamPathTemplate": "/Login",
      "UpstreamHttpMethod": [
        "POST"
      ]

    }
  ]
}

Here is my ocelot.json, when I hit GET https://localhost:44368/WeatherForecast it works fine. But when I post a user Login request with POST https://localhost:44368/Login it returns a 404 error. What I actually miss I can't find it out. But when I use a direct URL then it works.
swagger_result

Console Log
Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /Login, verb: POST
ocelot.json file
{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api​/WeatherForecast​/Get",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "44385"
        }
      ],
      "UpstreamPathTemplate": "/WeatherForecast",
      "UpstreamHttpMethod": [
        "GET"
      ]
    },
    {
      "DownstreamPathTemplate": "/api​/Auth​/Login",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "44320"
        }
      ],
      "UpstreamPathTemplate": "/Login",
      "UpstreamHttpMethod": [
        "POST"
      ]

    }
  ]
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓬勃野心 2025-01-30 13:13:05

我找到了解决我问题的解决方案,即基于环境变量,

  • ocelot.json
  • ocelot.development.json

我在ocelot.json文件上添加了下游映射,但是我的设置

 public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            webBuilder.UseStartup<Startup>();
            webBuilder.ConfigureAppConfiguration(config =>
            config.AddJsonFile($"ocelot.{env}.json"));
        });

总是找到一个始终发现的是, ocelot.development.json我没有将下游映射/login

I found the solution to my problem, that is there is two ocelot.json files based on the environment variable,

  • ocelot.json
  • ocelot.development.json

I added the downstream mapping on ocelot.json file, but my settings was

 public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            webBuilder.UseStartup<Startup>();
            webBuilder.ConfigureAppConfiguration(config =>
            config.AddJsonFile(
quot;ocelot.{env}.json"));
        });

it always finds the ocelot.development.json where I didn't put the downstream mapping for /Login

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文