如何使用HTTP调用Firebase可调用函数? [英] How to call Firebase Callable Functions with HTTP?
问题描述
我意识到,新的可调用云函数仍然可以像被调用一样被调用 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/json
或application/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屋!