且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 firebase 云功能向非谷歌服务器发送 POST 请求

更新时间:2023-02-26 13:44:25

注意:请求包已被弃用,如 npm 页面 request-npm.考虑使用其他替代方案,例如 axios

Note: request package has been deprecated as stated in the npm page request-npm. Consider using other alternatives like axios

这可以使用 request 模块完成:

This can be done using the request module:

// 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 定价页面所述,无法使用免费的 Spark 计划调用非 Google API>:

NOTE: This will only work on paid plans. It is not possible to call non-google APIs using the free Spark plan as explained on the Firebase pricing page:

Spark 计划只允许向 Google 拥有的服务发出出站网络请求.配额内允许入站调用请求.在 Blaze 计划中,Cloud Functions 提供永久免费层.每月免费提供前 2,000,000 次调用、400,000 GB 秒、200,000 CPU 秒和 5 GB 的 Internet 出口流量.您只需为超过此免费配额的使用量付费.定价基于调用总数和计算时间.计算时间根据为函数配置的内存和 CPU 量而变化.使用限制也通过每日和 100 秒配额强制执行.如需了解详情,请参阅云函数定价.

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.