How to call Firebase Callable Functions with HTTP?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 01:54:42

问题


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 

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


回答1:


EDIT: The details of the protocol have been formally documented now.

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.

Example body:

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

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.



来源:https://stackoverflow.com/questions/49476231/how-to-call-firebase-callable-functions-with-http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!