AWS API Gateway 是否可以支持带有正文和查询字符串参数的“application/x-www-form-urlencoded”?

Gro*_*ify 8 amazon-web-services query-string aws-api-gateway x-www-form-urlencoded

POST当使用正文中的 和其他参数发出请求时,许多服务可以接受 URL 中的查询字符串参数Content-Type: application/x-www-form-urlencoded,但 AWS API Gateway 似乎不能同时接受查询字符串参数。

POST当我使用映射模板和查询字符串 URL 参数(使用 Lambda 函数)调用 AWS API Gateway 时application/x-www-form-urlencoded,出现以下错误:

{
  "message":"When Content-Type:application/x-www-form-urlencoded,
    URL cannot include query-string parameters (after '?'):
    '/prod/webhook?inputType=wootric&outputType=glip&url=...'"
}
Run Code Online (Sandbox Code Playgroud)

下面是一个 cURL 示例:

curl -XPOST 'https://{myid}.execute-api.{myregion}.amazonaws.com/prod/webhook? \
inputType=wootric&outputType=glip&url=https://hooks.glip.com/webhook/ \
11112222-3333-4444-5555-666677778888' \
-d "@docs/handlers/wootric/event-example_response-created.txt" \
-H 'Content-Type: application/x-www-form-urlencoded' -v
Run Code Online (Sandbox Code Playgroud)

具体目标是使用带有查询字符串参数的 URL 将 Wootric Webhook 事件发布到 Lambda 函数。

您可以在这里获取代码:

https://github.com/grokify/chathooks

Woodric 事件正文文件位于此处:

https://raw.githubusercontent.com/grokify/chathooks/master/docs/handlers/wootric/event-example_response-created.txt

GitHub问题在这里:

https://github.com/grokify/chathooks/issues/15

错误消息似乎很明确,但我想问:

  1. 是否有解决方法来配置 API 网关以支持两者?
  2. AWS 是否有基于标准的原因不支持此功能,或者这只是一个设计决策/限制?

如果没有解决方案,除了部署像 Heroku 这样的托管服务器解决方案之外,是否还有一个好的轻量级解决方案。另外,其他云服务是否通过 API 网关 + 云功能支持此功能,例如 Google?

一些显示对两者支持的示例:

小智 -2

请将 HttpURLConnection 的请求属性设置为“Content-Type”、“application/json”,如下所示 connection.setRequestProperty("Content-Type", "application/json");