Ocelot post 请求未通过

Ocelot post request not going through

我在我的项目中实现了 Ocelot API 网关,它对 'GET' 请求工作正常,但是当我尝试发送 'POST' 请求时,我收到错误:

previousRequestId: no previous request id, message: Error Code: UnableToFindDownstreamRouteError Message: Failed to match ReRoute configuration for upstream path: /api/patient/CreateAppointment, verb: POST. errors found in ResponderMiddleware. Setting error response for request path:/api/patient/CreateAppointment, request method: POST

以下是我的ocelot.json:

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/patient/{everything}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "patientservice",
          "Port": 81
        }
      ],
      "UpstreamPathTemplate": "/api/patient/{everything}",
      "UpstreamHttpMethod": [ "GET", "POST" ],
      "UpstreamHost": "*"
    },
    {
      "DownstreamPathTemplate": "/api/actor",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "postgresqldapper",
          "Port": 5001
        }
      ],
      "UpstreamPathTemplate": "/api/actor",
      "UpstreamHttpMethod": [ "GET" ]
    },
    {
      "DownstreamPathTemplate": "/api/product/{everything}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "productservice",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/api/product/{everything}",
      "UpstreamHttpMethod": [ "GET" ]
    },
    {
      "DownstreamPathTemplate": "/api/weatherforecast",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "postgresqldapper",
          "Port": 5001
        }
      ],
      "UpstreamPathTemplate": "/api/weatherforecast",
      "UpstreamHttpMethod": [ "GET" ]
    },
    {
      "DownstreamPathTemplate": "/api/user",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "loginservicedapr",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/api/user",
      "UpstreamHttpMethod": [ "GET" ]
    },
    {
      "DownstreamPathTemplate": "/api/user/{everything}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "loginservicedapr",
          "Port": 5001
        }
      ],
      "UpstreamPathTemplate": "/api/user/{id}",
      "UpstreamHttpMethod": [ "GET" ]
    }

  ],
  "GlobalConfiguration": {
    "RequestIdKey": "OcRequestId",
    "AdministrationPath": "/administration"
  }
}

当直接从 Swagger 或 Postman 调用时,我正在对其执行 'POST' 请求的 API 对于 'POST' 请求工作正常。

请告诉我应该在 ocelot.json 文件中更改什么,以便 'POST' 请求可以通过?

您的错误实际上是说 Ocelot 无法将请求路由到

POST /api/patient/CreateAppointment

在您的屏幕截图中,您的 curl 命令(正在运行)是对以下内容的请求:

POST /api/patient

您的 /{everything} 路径后缀告诉 Ocelot 您调用网关的任何后缀都将出现在下游服务中。

我的理论是您没有在下游患者服务 API 上定义 CreateAppointment 端点操作。在您的服务上定义此路径后,您的 /api/patient/{everything} 路由映射应该可以正常工作。