【问题标题】:Is there anyway to access the XML payload in HTTP Trigger of Google Cloud Function or Firebase Cloud Function无论如何访问 Google Cloud Function 或 Firebase Cloud Function 的 HTTP 触发器中的 XML 有效负载
【发布时间】:2017-10-01 22:52:59
【问题描述】:

Google/Firebase Cloud Functions 看起来非常强大,可以快速实施 API。但是,与 Amazon 和 Azure 不同,如果调用者提交 application/xml 或 text/xml 有效负载,它们似乎会自动转换为 JSON 有效负载,并且不会使底层有效负载可用(req.body 为空)。

强制调用者提交 JSON 负载并不总是可控的,尤其是对于 WebHooks 类型的操作。

是否可以从 HTTP 触发器请求中检索原始 XML 有效负载,然后我们可以手动将其解析为 xml 并执行必要的操作。

感谢您的帮助。

【问题讨论】:

  • 带有 Cloud Functions for Firebase 的 HTTPS 函数由 Express.js 提供支持。请求和响应对象只是 Express Request 和 Response 对象。因此,无论您使用 Express 做什么,都可以使用 Cloud Functions。 expressjs.com

标签: google-app-engine firebase firebase-cloud-messaging google-cloud-functions


【解决方案1】:
request.rawBody.toString();

这暂时不适用于模拟器,但可以在 Google 的服务器上使用。我在 Firebase 上对其进行了测试。

请注意,您不能使用 request.pipe()(尽管它适用于模拟器...),因为请求有效负载在被处理到您的函数之前已被完全读取。

关于这个问题的讨论在这里: https://issuetracker.google.com/issues/36252545

【讨论】:

    猜你喜欢
    • 2020-08-31
    • 2020-10-26
    • 2022-09-28
    • 2022-08-16
    • 1970-01-01
    • 2020-05-13
    • 2020-07-26
    • 2018-05-16
    • 2018-10-01
    相关资源
    最近更新 更多