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

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

问题描述

我意识到,新的可调用云函数仍然可以像被调用一样被调用 HTTP事件,即仍可以在http://us-central1-$projectname.cloudfunctions.net/$functionname下访问它们.这样做时,我的 Cloud Functions Log 中收到一条错误消息:

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必须使用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天全站免登陆