当我使用 <form> 时如何获取查询参数使用 POST 方法触发 Firebase http 功能? [英] How to get query params when I use <form> with POST method to trigger Firebase http functions?

查看:14
本文介绍了当我使用 <form> 时如何获取查询参数使用 POST 方法触发 Firebase http 功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以安全的方式将一些查询参数传递给我在 Firebase 中的 http 函数.我的参数并不像密码等那样敏感,它们是一些布尔值等,它们决定了逻辑服务器端.

I am trying to pass some query params to my http function in Firebase in a secure way. My params are not really sensitive like passwords, etc, they are some booleans, etc that determines logic server side.

当我尝试使用 GETPUT 方法的简单 <form> 时,res.query 会显示我使用 POST 时的值不是.

When I try a simple <form> with method GET or PUT the res.query shows the values not when I use POST.

  <form id="form" action="https://us-central1-***.cloudfunctions.net/myfuncName" 
   method="post">
  <input type="text" name="id" value="test">
  </form>

我通过

this.getElementById("form").submit();

在我的功能中我有:

function(req, res) {
    const param = req.query;
    console.log('query param is ' , param); //{} when form method is POST 
}

我希望能够在我的函数中从 res.query 获取 id,但我得到了 null {}.如果我将方法更改为 GET 或 PUT,那么我会看到 {id:test}.

任何有关增强此安全性的建议也将不胜感激.谢谢.

Any suggestion on enhancing the security of this would be appreciate too. Thanks.

推荐答案

res.query 允许您从请求的查询字符串中获取参数.POST 请求不使用查询字符串,因此您不能使用 res.query.POST 将参数发送到请求正文.

res.query allows you to get parameters coming from the query string of a request. A POST request doesn't use the query string, so you can't use res.query. POST sends parameters to the request body.

要访问来自表单的请求正文中的 POST 参数,您可以使用 云函数文档.

To access POST parameters in the request body that are coming form a form, you can use req.body as described in the Cloud Functions documentation.

这篇关于当我使用 &lt;form&gt; 时如何获取查询参数使用 POST 方法触发 Firebase http 功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆