2017-04-14 92 views
14

我想知道是否有可能使用firebase云功能发送一个post服务请求到非谷歌服务器(从我能找到我需要的大火计划为了与非谷歌服务器进行交互)使用firebase云功能发送POST请求到非谷歌服务器

基本上我想POST到运行在arduino上的外部服务器,只要值被添加到我的数据库。

我查看了文档,发现有云功能响应HTTP发布请求(HTTP云功能)的示例,但似乎无法找到发布到外部服务器的任何示例。这可能吗?

+2

考虑使用节点的请求承诺库,使传出HTTP请求。 https://github.com/request/request-promise –

+0

做'服务'功能还需要付费计划吗? – leopragi

回答

19

这可以通过使用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 .

+2

还需要付费的Firebase帐户 - 适用于Blaze计划 – Arkelyan

+4

如果您的请求属于其他Google拥有的服务,则此功能可用于未付帐户(Spark计划)。 “Spark计划只允许向Google拥有的服务发出出站网络请求,并在配额内允许入站调用请求。” (https://firebase.google.com/pricing/) –

+1

我得到了'错误:解析触发器时出错:使用'var request = require('request')'执行Firebase部署时找不到模块'request'';' – matth

相关问题