豹子邮寄请求未通过

问题描述 投票:1回答:1

我已经在我的项目中实现了Ocelot api网关,该网关对于'GET'请求可以正常工作,但是当我尝试发送'POST'请求时,出现了错误:previousRequestId:无先前的请求ID,消息:错误代码:UnableToFindDownstreamRouteError消息:未能匹配上游路径/ api / Patient / CreateAppointment的ReRoute配置,动词: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'请求可以正常工作。Swagger image请让我知道我应该在ocelot.json文件中进行哪些更改,以便'POST'请求可以通过?

.net asp.net-web-api microservices core ocelot
1个回答
1
投票

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

POST /api/patient/CreateAppointment

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

POST /api/patient

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

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

© www.soinside.com 2019 - 2024. All rights reserved.