【问题标题】:how to pass parameters when creating a services kong api创建服务kong api时如何传递参数
【发布时间】:2019-03-14 18:25:48
【问题描述】:

我正在尝试在 kong 中创建一个服务,它的 url 接收路径变量“example / {id} / example”,但 kong 抛出以下异常

curl 创建服务

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}

请帮忙

【问题讨论】:

    标签: api microservices kong


    【解决方案1】:

    这是因为你的路径没有编码

    来自validate_path

    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 选项来对您的数据进行 url 编码,而不是 -d。或者只是将路径设置为/v1/%7Bfolio%7D/ejemplo%26name%3Dname-services

    【讨论】:

    • 感谢您的回复,但是您无法使用动态参数设置路径,[github.com/Kong/kong/issues/677#issuecomment-155883807] 但在这篇文章中我找到了解决方案
    • 抱歉读了一点,也许你可以回答你的问题并总结一下你的解决方案是什么@MarioAaronGonzalezSanchez?
    【解决方案2】:

    我在thiskonghq 中发现你可以在 URI 中使用正则表达式。

    将路线映射为/example/\d+/example 对我有用。

    【讨论】:

      猜你喜欢
      • 2021-06-18
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 2016-05-10
      • 2014-09-11
      • 2022-01-23
      相关资源
      最近更新 更多