我已经在我的项目中实现了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”请求可以正常工作。 请让我知道我应该在ocelot.json文件中进行哪些更改,以便“ POST”请求可以通过?
答案 0 :(得分:1)
您的错误实际上是在说Ocelot无法将请求路由到
POST /api/patient/CreateAppointment
在屏幕截图中,您的curl命令(正在运行)是对以下内容的请求:
POST /api/patient
您的/{everything}
路径后缀告诉Ocelot,与网关一起调用的任何后缀都将出现在下游服务上。
我的理论是您尚未在下游患者服务API上定义 CreateAppointment 端点操作。在服务上定义此路径后,/api/patient/{everything}
路由映射应该可以正常工作。