我在我的项目中实现了Ocelot网关,该网关对“GET”请求很好,但是当我试图发送'POST‘请求时,我得到了错误:
previousRequestId:没有先前的请求id,message: Error Code: UnableToFindDownstreamRouteError Message:未能匹配针对上游路径的ReRoute配置:/api/previousRequestId/CreateAppointment,谓词: POST。在ResponderMiddleware中发现错误。设置请求路径的错误响应:/api/病人/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”请求时,我所做的“POST”请求的API工作正常。

请让我知道我应该在ocelot.json文件中更改什么,这样'POST‘请求才能通过?
发布于 2020-05-29 12:58:03
您的错误实际上是说Ocelot无法将请求路由到
POST /api/patient/CreateAppointment在屏幕截图中,curl命令(正在工作)是请求:
POST /api/patient您的/{everything}路径后缀告诉Ocelot,您在网关中调用的任何后缀都将出现在下游服务上。
我的理论是,您还没有在下游的病人服务API上定义CreateAppointment端点操作。一旦您在服务上定义了此路径,您的/api/patient/{everything}路由映射就会正常工作。
https://stackoverflow.com/questions/62079047
复制相似问题