我想知道是否有可能使用firebase云功能发送一个post服务请求到非谷歌服务器(从我能找到我需要的大火计划为了与非谷歌服务器进行交互)使用firebase云功能发送POST请求到非谷歌服务器
基本上我想POST到运行在arduino上的外部服务器,只要值被添加到我的数据库。
我查看了文档,发现有云功能响应HTTP发布请求(HTTP云功能)的示例,但似乎无法找到发布到外部服务器的任何示例。这可能吗?
我想知道是否有可能使用firebase云功能发送一个post服务请求到非谷歌服务器(从我能找到我需要的大火计划为了与非谷歌服务器进行交互)使用firebase云功能发送POST请求到非谷歌服务器
基本上我想POST到运行在arduino上的外部服务器,只要值被添加到我的数据库。
我查看了文档,发现有云功能响应HTTP发布请求(HTTP云功能)的示例,但似乎无法找到发布到外部服务器的任何示例。这可能吗?
这可以通过使用request
模块来完成:
// import the module
var request = require('request');
// make the request
request('put your external url here', function (error, response, body) {
if (!error && response.statusCode == 200) {
//here put what you want to do with the request
}
})
注意:这只会工作,在支付计划。这是不可能使用免费的星火计划为在Firebase pricing page解释调用非谷歌的API:
The Spark plan allows outbound network requests only to Google-owned services. Inbound invocation requests are allowed within the quota. On the Blaze plan, Cloud Functions provides a perpetual free tier. The first 2,000,000 invocations, 400,000 GB-sec, 200,000 CPU-sec, and 5 GB of Internet egress traffic is provided for free each month. You are only charged on usage past this free allotment. Pricing is based on total number of invocations, and compute time. Compute time is variable based on the amount of memory and CPU provisioned for a function. Usage limits are also enforced through daily and 100s quotas. For more information, see Cloud Functions Pricing .
您需要安装德包。 转到火力点,Funcions目录在终端输入
npm install request
OR
npm install request-promise
考虑使用节点的请求承诺库,使传出HTTP请求。 https://github.com/request/request-promise –
做'服务'功能还需要付费计划吗? – leopragi