有没有办法告诉 Ocelot 一个参数是可选的?
假设下面的查询参数是可选的:
"DownstreamPathTemplate": "/api/SearchAPI/?query={query}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5000
}
],
"UpstreamPathTemplate": "/api/SearchAPI/?query={query}",
"UpstreamHttpMethod": [ "GET" ],
"FileCacheOptions": {
"TtlSeconds": 60
}
如果我向 /SearchAPI/?query=
发送请求,我会收到 404
作为响应。我需要复制 Upstream
以不使用参数来修复。还有其他方法可以解决这个问题吗?
最佳答案
你可以像这样使用{everything}
"DownstreamPathTemplate": "/api/SearchAPI/{everything}"
关于asp.net-core - Ocelot API 网关可选参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59637188/