我正在尝试在kong中创建一个服务,该服务的url接收路径变量“ example / {id} / example”,但是kong抛出以下异常
卷曲以创建服务
curl -i -X POST --url http://localhost:8001/services/ -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d "protocol=http&host=localhost&port=8090&path=/v1/{folio}/ejemplo&name=name-services"
创建此内容时例外
{"strategy":"postgres","message":"schema violation (path: invalid path: '\/v1\/{folio}\/ejemplo' (characters outside of the reserved list of RFC 3986 found))","name":"schema violation","fields":{"path":"invalid path: '\/v1\/{folio}\/ejemplo' (characters outside of the reserved list of RFC 3986 found)"},"code":2}
请帮助
答案 0 :(得分:1)
这是因为您的路径未编码
local function validate_path(path)
if not string.match(path, "^/[%w%.%-%_~%/%%]*$") then
return nil,
"invalid path: '" .. path ..
"' (characters outside of the reserved list of RFC 3986 found)",
"rfc3986"
end
您可以在curl中使用--data-urlencode
选项而不是-d
来对数据进行url编码。或者,只需将路径设置为/v1/%7Bfolio%7D/ejemplo%26name%3Dname-services
答案 1 :(得分:0)
我在 this konghq 中找到讨论您可以在 URI 中使用正则表达式。
将路线映射为 /example/\d+/example
对我有用。