首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ocelot post请求未通过

Ocelot post请求未通过
EN

Stack Overflow用户
提问于 2020-05-29 05:04:33
回答 1查看 6K关注 0票数 1

我在我的项目中实现了Ocelot网关,该网关对“GET”请求很好,但是当我试图发送'POST‘请求时,我得到了错误:

previousRequestId:没有先前的请求id,message: Error Code: UnableToFindDownstreamRouteError Message:未能匹配针对上游路径的ReRoute配置:/api/previousRequestId/CreateAppointment,谓词: POST。在ResponderMiddleware中发现错误。设置请求路径的错误响应:/api/病人/CreateAppointment,请求方法: POST

以下是我的ocelot.json:

代码语言:javascript
复制
{
  "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”请求时,我所做的“POST”请求的API工作正常。

请让我知道我应该在ocelot.json文件中更改什么,这样'POST‘请求才能通过?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-29 12:58:03

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

代码语言:javascript
复制
POST /api/patient/CreateAppointment

在屏幕截图中,curl命令(正在工作)是请求:

代码语言:javascript
复制
POST /api/patient

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

我的理论是,您还没有在下游的病人服务API上定义CreateAppointment端点操作。一旦您在服务上定义了此路径,您的/api/patient/{everything}路由映射就会正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62079047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档