HTTP POST Google Cloud Functions NodeJS

编程入门 行业动态 更新时间:2024-10-28 14:27:01
本文介绍了HTTP POST Google Cloud Functions NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我该如何编写Google Cloud Function来接收HTTP请求,然后将HTTP POST请求发送到其他端点?

How do I write a Google Cloud Function that will receive a HTTP request and then send a HTTP POST request to a different endpoint?

例如

  • 我可以将HTTP触发器发送到我的云函数( https ://us-central1-plugin-check-xxxx.cloudfunctions/test ).我正在使用exports.test = function helloWorld(req, res){}处理接收到的数据.

  • I can send the HTTP trigger to my cloud function (us-central1-plugin-check-xxxx.cloudfunctions/test). I am using exports.test = function helloWorld(req, res){} to process the data received.

然后我想将具有HTTP POST请求的已处理数据发送到另一个端点.

And then I want to send the processed data with a HTTP POST request to a different endpoint.

到目前为止,我已经尝试通过 node-webhooks发送HTTP POST,请求& restler 模块,但它们似乎都不起作用.是因为这些模块与 exports.test 一起使用?

By far I have tried sending HTTP POST with node-webhooks, request & restler modules but none of them seem to work. Is it because these modules are used in conjunction with exports.test ?

我的问题与此问题,但答案并没有帮助我.

My question is related to this question but the answers didn't help me.

要发送到终结点的数据位于 json &中. 内容类型:application/json .

The data being sent to endpoint is in json & Content-type: application/json.

var request = require('request'); //also tried for node-webhook, restler modules exports.test = function(req, res) { //processing of received json data from source A. } function sendToEndpoint(processed_data) { let abc = processed_data; //send processed data to source B request.post({ uri: 'example', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(abc) }); }

推荐答案

正如@RenaudTarnec在评论中提到的那样,问题在于未配置我的计费帐户.

As @RenaudTarnec mentioned in the comments the problem was that my billing account was not configured.

Google不允许在没有有效的帐单信息的情况下向外部服务器发出出站请求,以防止任何恶意活动.

Google doesn't allow outbound requests to external servers without valid billing info so as to prevent any malicious activity.

配置计费帐户后,我可以发出出站请求,问题中提到的所有节点模块都可以工作.

After configuring a billing account I was able to make outbound requests and all the node-modules mentioned in the question worked.

更多推荐

HTTP POST Google Cloud Functions NodeJS

本文发布于:2023-10-12 00:30:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Google   POST   HTTP   NodeJS   Functions

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!