如何使用 HTTP 调用 Firebase 可调用函数? [英] How to call Firebase Callable Functions with HTTP?

查看:27
本文介绍了如何使用 HTTP 调用 Firebase 可调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到新的 Callable Cloud Functions 仍然可以像调用它们一样被调用HTTP 事件,即它们仍然可以通过 http://访问us-central1-$projectname.cloudfunctions.net/$functionname.执行此操作时,我在 Cloud Functions 日志中收到一条错误消息:

I realised that the new Callable Cloud Functions can still be called as if they were HTTP events, i.e. they can still be reached under http://us-central1-$projectname.cloudfunctions.net/$functionname. When doing that I receive an error message in my Cloud Functions Log:

Request has invalid method. GET 

这意味着 HTTP-GET 不起作用,但是有没有办法调用这些函数?也许他们正在使用 HTTP-CONNECT.

This means that HTTP-GET does not work, but is there a way to call the functions? Maybe they are using HTTP-CONNECT.

推荐答案

协议的细节已经 现在正式记录.

HTTPS Callable 函数必须使用 POST 方法调用,Content-Type 必须是 application/jsonapplication/json;charset=utf-8,并且正文必须包含一个名为 data 的字段,以便将数据传递给方法.

HTTPS Callable functions must be called using the POST method, the Content-Type must be application/json or application/json; charset=utf-8, and the body must contain a field called data for the data to be passed to the method.

示例正文:

{
    "data": {
        "aString": "some string",
        "anInt": 57,
        "aFloat": 1.23
    }
}

如果您通过创建自己的 http 请求来调用函数,您可能会发现改用常规 HTTPS 函数更灵活.

If you are calling a function by creating your own http request, you may find it more flexible to use a regular HTTPS function instead.

这篇关于如何使用 HTTP 调用 Firebase 可调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆