1

我已经在我的项目中实现了 Ocelot API 网关,该网关对于“GET”请求运行良好,但是当我尝试发送“POST”请求时出现错误:

previousRequestId:没有先前的请求 id,消息:错误代码:UnableToFindDownstreamRouteError 消息:无法匹配上游路径的 ReRoute 配置:/api/patient/CreateAppointment,动词:POST。在 ResponderMiddleware 中发现错误。请求路径设置错误响应:/api/patient/CreateAppointment,请求方法: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”请求可以通过?

4

1 回答 1

1

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

POST /api/patient/CreateAppointment

在您的屏幕截图中,您的 curl 命令(正在运行)是一个请求:

POST /api/patient

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

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

于 2020-05-29T12:58:03.447 回答