[来自Google Cloud Functions Node.js的HTTP POST?

问题描述 投票:0回答:1

已经提出了类似的问题,但是建议的答案需要request.post,但是现在不建议使用“ request”。没有关于替代方法的建议。HTTP POST Google Cloud Functions NodeJS

问题:

我已经找了两天了。我只是在寻找一些示例代码来发送来自Google Cloud Function的POST请求。我将传递少量数据和auth令牌,但无法找出正确的方法。

我将通过HTTPS网址访问API,并传递以下参数:

-d arg="1234" (a string)
-d access_token=0809809cx089009xci3 (an access token)

[关于如何从POST触发云功能,但是没有关于如何从云功能内部实际生成POST的文档,有上百万。

提前感谢!

node.js google-cloud-functions http-post
1个回答
0
投票

您可以使用“ request”以外的其他库,例如:gotaxios或标准节点库中的默认“ HTTP”模块。结帐5 Ways to Make HTTP Requests in Node.js

这里是使用“ got”的实现:

const got = require('got');

const searchParams = new URLSearchParams([
  ['arg', '1234'],
  ['access_token', '0809809cx089009xci3'],
]);

got.post('https://example.com', { searchParams });
© www.soinside.com 2019 - 2024. All rights reserved.